-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8354556: Expand value-based class warnings to java.lang.ref API #24746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8354556: Expand value-based class warnings to java.lang.ref API #24746
Conversation
👋 Welcome back vromero! A progress list of the required criteria for merging this PR into |
@vicente-romero-oracle This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 3 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
@vicente-romero-oracle The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add handling of RequiresIdentity
in createAnnotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update on CreateSymbols, the complete implementation with the changes for CreateSymbols should be included in the PR for [1]. Which will be developed in parallel to this proposal
@@ -4249,6 +4249,14 @@ compiler.warn.declared.using.preview=\ | |||
compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class=\ | |||
attempt to synchronize on an instance of a value-based class | |||
|
|||
# lint: identity | |||
compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class2=\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different from the message with no 2 suffix? Is there a reason why one localization entry is required for one type of lint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the requirement is for the identity lint warning to be an alias of the synchronization warning
|
FYI, this issue now effectively fixes JDK-7004476 Lint.LintCategory should support aliases, which happened to be closed as "Rejected" on Monday. Not sure if anything needs to be done. |
I guess we can add a note to that bug once this one goes through |
I'm coming here from "far away" and am not familiar with all the work leading Keeping that in mind, I'm surprised by some parts of this change. Specifically
I wonder why it is not sufficient to apply the annotation to the type The type parameter of the subclasses is passed as the type parameter to Similarly, I wonder why the constructors need the annotation. And why don't |
@@ -5667,4 +5668,193 @@ private <E extends Element> Void runUnderLint(E symbol, JCClassDecl p, BiConsume | |||
|
|||
} | |||
|
|||
void checkRequiresIdentity(JCTree tree, Lint lint) { | |||
switch (tree) { | |||
case JCClassDecl classDecl : { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - unless fall-through is needed (it does not seem to be, on the first sight), I would suggest to use ->
instead of :
, esp. given the cases use blocks anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javac changes look overall good to me. One question and some comments for consideration inline.
@@ -2672,6 +2670,9 @@ public void visitApply(JCMethodInvocation tree) { | |||
Type capturedRes = resultInfo.checkContext.inferenceContext().cachedCapture(tree, restype, true); | |||
result = check(tree, capturedRes, KindSelector.VAL, resultInfo); | |||
} | |||
if (env.info.lint.isEnabled(LintCategory.IDENTITY)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only place where there's a check whether the lint is enabled before the call to checkRequiresIdentity
. Is there a reason for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left over of the initial approach I guess. I will remove it
@@ -5667,4 +5668,193 @@ private <E extends Element> Void runUnderLint(E symbol, JCClassDecl p, BiConsume | |||
|
|||
} | |||
|
|||
void checkRequiresIdentity(JCTree tree, Lint lint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consideration: as far as I can see, we have a sharp(er) type when we call checkRequiresIdentity
, but we give up the type, and re-instante it here using the pattern matching switch. I wonder if it would be more elegant (and hopefully not really too much longer) if the checkRequiresIdentity
method would have multiple overloads, with the sharp(er) types, like JCClassDecl
/JCVariableDecl
, etc.
Or is there a reason to given up the sharp(er) type and re-create it using the switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the motivation was to have all this related code in one place, if this code is split into several overloaded methods then I guess an entity, a class, should probably be defined to contain all this code. Dunno I guess the current solution seemed more self-contained to me
if (t != null && t.tsym != null) { | ||
SymbolMetadata sm = t.tsym.getMetadata(); | ||
if (sm != null && !t.getTypeArguments().isEmpty()) { | ||
for (Attribute.TypeCompound ta: sm.getTypeAttributes().stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code here, and the code in checkIfTypeParamsRequiresIdentity
look similar a lot (although they manipulate List<Type>
and List<JCExpression>
, of course. I wonder if there's a chance to share the code, at least partially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rewritten both using streams, technically we could still reuse some code but not a big amount of it, dunno
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javac changes look good to me, with one trivial nit in Check
.
CompilerProperties.LintWarnings.AttemptToUseValueBasedWhereIdentityExpected)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - there appears to be an extra space at the beginning of this line.
@@ -304,13 +304,18 @@ public void createSymbols(String ctDescriptionFileExtra, String ctDescriptionFil | |||
"Ljdk/internal/ValueBased;"; | |||
private static final String VALUE_BASED_ANNOTATION_INTERNAL = | |||
"Ljdk/internal/ValueBased+Annotation;"; | |||
private static final String REQUIRES_IDENTITY_ANNOTATION = | |||
"Ljdk/internal/RequieresIdentity;"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: RequieresIdentity -> RequiresIdentity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javac changes look good to me.
thanks for the reviews, rerunning tests before pushing |
/integrate |
thanks guys for the reviews and contributions |
Going to push as commit 637e9d1.
Your commit was automatically rebased without conflicts. |
@vicente-romero-oracle Pushed as commit 637e9d1. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This PR is defining a new internal annotation,
@jdk.internal.RequiresIdentity
, with target types PARAMETER and TYPE_PARAMETER. The @RequiresIdentity annotation expresses the expectation that an argument to a given method or constructor parameter will be an object with a unique identity, not an instance of a value-based class; or that the type argument to a given type parameter will not be a value-based class type.For more details please refer to the complete description in the corresponding JIRA entry [1]
TIA
[1] https://bugs.openjdk.org/browse/JDK-8354556
Progress
Issues
Reviewers
Contributors
<acobbs@openjdk.org>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24746/head:pull/24746
$ git checkout pull/24746
Update a local copy of the PR:
$ git checkout pull/24746
$ git pull https://git.openjdk.org/jdk.git pull/24746/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24746
View PR using the GUI difftool:
$ git pr show -t 24746
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24746.diff
Using Webrev
Link to Webrev Comment