-
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
Changes from all commits
950f391
4c4aebe
0979978
d35ef50
ed64f22
e6c17f7
d40e285
5a0b6bf
434dda7
9f0407a
2697858
b4f5329
ac28815
5491f39
09b8331
9d6af78
4a6b9bc
1c3cd61
84b52a6
70e0311
5e3acc9
1134ffe
151908a
60f1f53
ad7f617
5d834ce
d52ec33
1ff2f2c
ea63116
a9a5378
3c6dacb
973307e
63fd151
22acaf2
bdbcd33
6c8d2b1
def2505
cf92614
904bd4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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/RequiresIdentity;"; | ||
| private static final String REQUIRES_IDENTITY_ANNOTATION_INTERNAL = | ||
| "Ljdk/internal/RequiresIdentity+Annotation;"; | ||
| public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>( | ||
| List.of("Ljdk/Profile+Annotation;", | ||
| "Lsun/Proprietary+Annotation;", | ||
| PREVIEW_FEATURE_ANNOTATION_OLD, | ||
| PREVIEW_FEATURE_ANNOTATION_NEW, | ||
| VALUE_BASED_ANNOTATION, | ||
| RESTRICTED_ANNOTATION)); | ||
| RESTRICTED_ANNOTATION, | ||
| REQUIRES_IDENTITY_ANNOTATION)); | ||
|
|
||
| private void stripNonExistentAnnotations(LoadDescriptions data) { | ||
| Set<String> allClasses = data.classes.name2Class.keySet(); | ||
|
|
@@ -1021,6 +1026,12 @@ private Annotation createAnnotation(AnnotationDescription desc) { | |
| annotationType = VALUE_BASED_ANNOTATION_INTERNAL; | ||
| } | ||
|
|
||
| if (REQUIRES_IDENTITY_ANNOTATION.equals(annotationType)) { | ||
| //the non-public RequiresIdentity annotation will not be available in ct.sym, | ||
| //replace with purely synthetic javac-internal annotation: | ||
| annotationType = REQUIRES_IDENTITY_ANNOTATION_INTERNAL; | ||
| } | ||
|
|
||
| if (RESTRICTED_ANNOTATION.equals(annotationType)) { | ||
| //the non-public Restricted annotation will not be available in ct.sym, | ||
| //replace with purely synthetic javac-internal annotation: | ||
|
|
@@ -2202,6 +2213,7 @@ private boolean readAttribute(FeatureDescription feature, Attribute<?> attr) { | |
| chd.permittedSubclasses = a.permittedSubclasses().stream().map(ClassEntry::asInternalName).collect(Collectors.toList()); | ||
| } | ||
| case ModuleMainClassAttribute a -> ((ModuleHeaderDescription) feature).moduleMainClass = a.mainClass().asInternalName(); | ||
| case RuntimeVisibleTypeAnnotationsAttribute a -> {/* do nothing for now */} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will make createsymbol created older reference/weakhashmap APIs' type parameter for older releases always have this annotation; but this should be fine. We can fix this for 26. The question is that now their type parameter and the actual parameter uses will see some inconsistent values for releases < 25 in the future.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jan is taking a look at the changes for CreateSymbols. The change included in this PR is the minimum for the build to pass, I will double check with him if what he is doing will be pushed in a separate PR or as part of this PR, not sure yet. Time is tight and we want this in 25 this is why I decided to move on with this PR even though the CreateSymbols code complete. I forgot to mention this before, sorry |
||
| default -> throw new IllegalArgumentException("Unhandled attribute: " + attr.attributeName()); // Do nothing | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Oracle designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| package jdk.internal; | ||
|
|
||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.ElementType.PARAMETER; | ||
| import static java.lang.annotation.ElementType.TYPE_PARAMETER; | ||
|
|
||
| /** | ||
| * Indicates that the annotated parameter or type parameter is not expected to be a | ||
| * Value Based class. | ||
| * Using a parameter or type parameter of a <a href="../lang/doc-files/ValueBased.html">value-based classes</a> | ||
| * should produce warnings about behavior that is inconsistent with identity based semantics. | ||
| * | ||
| * Note this internal annotation is handled specially by the javac compiler. | ||
| * To work properly with {@code --release older-release}, it requires special | ||
| * handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java} | ||
| * and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}. | ||
| * | ||
| * @since 25 | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(value={PARAMETER, TYPE_PARAMETER}) | ||
| public @interface RequiresIdentity { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,4 +46,3 @@ | |
| @Target(value={TYPE}) | ||
| public @interface ValueBased { | ||
| } | ||
|
|
||
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
RequiresIdentityincreateAnnotationThere 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
[1] https://bugs.openjdk.org/browse/JDK-8356894