8333560: -Xlint:restricted does not work with --release

Co-authored-by: Jan Lahoda <jlahoda@openjdk.org>
Reviewed-by: vromero, mcimadamore
This commit is contained in:
Jorn Vernee 2024-06-06 15:18:18 +00:00
parent 606df44141
commit 02f240415c
5 changed files with 20 additions and 6 deletions

View File

@ -340,6 +340,10 @@ public class CreateSymbols {
"Ljdk/internal/javac/PreviewFeature;";
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
"Ljdk/internal/PreviewFeature+Annotation;";
private static final String RESTRICTED_ANNOTATION =
"Ljdk/internal/javac/Restricted;";
private static final String RESTRICTED_ANNOTATION_INTERNAL =
"Ljdk/internal/javac/Restricted+Annotation;";
private static final String VALUE_BASED_ANNOTATION =
"Ljdk/internal/ValueBased;";
private static final String VALUE_BASED_ANNOTATION_INTERNAL =
@ -349,7 +353,8 @@ public class CreateSymbols {
"Lsun/Proprietary+Annotation;",
PREVIEW_FEATURE_ANNOTATION_OLD,
PREVIEW_FEATURE_ANNOTATION_NEW,
VALUE_BASED_ANNOTATION));
VALUE_BASED_ANNOTATION,
RESTRICTED_ANNOTATION));
private void stripNonExistentAnnotations(LoadDescriptions data) {
Set<String> allClasses = data.classes.name2Class.keySet();
@ -1247,6 +1252,12 @@ public class CreateSymbols {
annotationType = VALUE_BASED_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:
annotationType = RESTRICTED_ANNOTATION_INTERNAL;
}
return new Annotation(null,
addString(constantPool, annotationType),
createElementPairs(constantPool, values));

View File

@ -222,6 +222,7 @@ public class Symtab {
public final Type previewFeatureType;
public final Type previewFeatureInternalType;
public final Type restrictedType;
public final Type restrictedInternalType;
public final Type typeDescriptorType;
public final Type recordType;
public final Type switchBootstrapsType;
@ -609,6 +610,7 @@ public class Symtab {
previewFeatureType = enterClass("jdk.internal.javac.PreviewFeature");
previewFeatureInternalType = enterSyntheticAnnotation("jdk.internal.PreviewFeature+Annotation");
restrictedType = enterClass("jdk.internal.javac.Restricted");
restrictedInternalType = enterSyntheticAnnotation("jdk.internal.javac.Restricted+Annotation");
typeDescriptorType = enterClass("java.lang.invoke.TypeDescriptor");
recordType = enterClass("java.lang.Record");
switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");

View File

@ -1544,7 +1544,7 @@ public class ClassReader {
} else if (proxy.type.tsym.flatName() == syms.valueBasedInternalType.tsym.flatName()) {
Assert.check(sym.kind == TYP);
sym.flags_field |= VALUE_BASED;
} else if (proxy.type.tsym.flatName() == syms.restrictedType.tsym.flatName()) {
} else if (proxy.type.tsym.flatName() == syms.restrictedInternalType.tsym.flatName()) {
Assert.check(sym.kind == MTH);
sym.flags_field |= RESTRICTED;
} else {

View File

@ -3,6 +3,7 @@
* @bug 8316971
* @summary Smoke test for restricted method call warnings
* @compile/fail/ref=RestrictedMethods.out -Xlint:restricted -Werror -XDrawDiagnostics RestrictedMethods.java
* @compile/fail/ref=RestrictedMethods.out --release ${jdk.version} -Xlint:restricted -Werror -XDrawDiagnostics RestrictedMethods.java
* @compile -Werror RestrictedMethods.java
*/

View File

@ -1,7 +1,7 @@
RestrictedMethods.java:14:44: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
RestrictedMethods.java:18:49: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
RestrictedMethods.java:24:27: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
RestrictedMethods.java:33:16: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
RestrictedMethods.java:15:44: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
RestrictedMethods.java:19:49: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
RestrictedMethods.java:25:27: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
RestrictedMethods.java:34:16: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
- compiler.err.warnings.and.werror
1 error
4 warnings