Skip to content

Commit 02f2404

Browse files
JornVerneelahodaj
andcommitted
8333560: -Xlint:restricted does not work with --release
Co-authored-by: Jan Lahoda <[email protected]> Reviewed-by: vromero, mcimadamore
1 parent 606df44 commit 02f2404

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ public void createSymbols(String ctDescriptionFileExtra, String ctDescriptionFil
340340
"Ljdk/internal/javac/PreviewFeature;";
341341
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
342342
"Ljdk/internal/PreviewFeature+Annotation;";
343+
private static final String RESTRICTED_ANNOTATION =
344+
"Ljdk/internal/javac/Restricted;";
345+
private static final String RESTRICTED_ANNOTATION_INTERNAL =
346+
"Ljdk/internal/javac/Restricted+Annotation;";
343347
private static final String VALUE_BASED_ANNOTATION =
344348
"Ljdk/internal/ValueBased;";
345349
private static final String VALUE_BASED_ANNOTATION_INTERNAL =
@@ -349,7 +353,8 @@ public void createSymbols(String ctDescriptionFileExtra, String ctDescriptionFil
349353
"Lsun/Proprietary+Annotation;",
350354
PREVIEW_FEATURE_ANNOTATION_OLD,
351355
PREVIEW_FEATURE_ANNOTATION_NEW,
352-
VALUE_BASED_ANNOTATION));
356+
VALUE_BASED_ANNOTATION,
357+
RESTRICTED_ANNOTATION));
353358

354359
private void stripNonExistentAnnotations(LoadDescriptions data) {
355360
Set<String> allClasses = data.classes.name2Class.keySet();
@@ -1247,6 +1252,12 @@ private Annotation createAnnotation(List<CPInfo> constantPool, AnnotationDescrip
12471252
annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
12481253
}
12491254

1255+
if (RESTRICTED_ANNOTATION.equals(annotationType)) {
1256+
//the non-public Restricted annotation will not be available in ct.sym,
1257+
//replace with purely synthetic javac-internal annotation:
1258+
annotationType = RESTRICTED_ANNOTATION_INTERNAL;
1259+
}
1260+
12501261
return new Annotation(null,
12511262
addString(constantPool, annotationType),
12521263
createElementPairs(constantPool, values));

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public static Symtab instance(Context context) {
222222
public final Type previewFeatureType;
223223
public final Type previewFeatureInternalType;
224224
public final Type restrictedType;
225+
public final Type restrictedInternalType;
225226
public final Type typeDescriptorType;
226227
public final Type recordType;
227228
public final Type switchBootstrapsType;
@@ -609,6 +610,7 @@ public <R, P> R accept(ElementVisitor<R, P> v, P p) {
609610
previewFeatureType = enterClass("jdk.internal.javac.PreviewFeature");
610611
previewFeatureInternalType = enterSyntheticAnnotation("jdk.internal.PreviewFeature+Annotation");
611612
restrictedType = enterClass("jdk.internal.javac.Restricted");
613+
restrictedInternalType = enterSyntheticAnnotation("jdk.internal.javac.Restricted+Annotation");
612614
typeDescriptorType = enterClass("java.lang.invoke.TypeDescriptor");
613615
recordType = enterClass("java.lang.Record");
614616
switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ else if (proxy.type.tsym.flatName() == syms.profileType.tsym.flatName()) {
15441544
} else if (proxy.type.tsym.flatName() == syms.valueBasedInternalType.tsym.flatName()) {
15451545
Assert.check(sym.kind == TYP);
15461546
sym.flags_field |= VALUE_BASED;
1547-
} else if (proxy.type.tsym.flatName() == syms.restrictedType.tsym.flatName()) {
1547+
} else if (proxy.type.tsym.flatName() == syms.restrictedInternalType.tsym.flatName()) {
15481548
Assert.check(sym.kind == MTH);
15491549
sym.flags_field |= RESTRICTED;
15501550
} else {

test/langtools/tools/javac/RestrictedMethods.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @bug 8316971
44
* @summary Smoke test for restricted method call warnings
55
* @compile/fail/ref=RestrictedMethods.out -Xlint:restricted -Werror -XDrawDiagnostics RestrictedMethods.java
6+
* @compile/fail/ref=RestrictedMethods.out --release ${jdk.version} -Xlint:restricted -Werror -XDrawDiagnostics RestrictedMethods.java
67
* @compile -Werror RestrictedMethods.java
78
*/
89

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
RestrictedMethods.java:14:44: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
2-
RestrictedMethods.java:18:49: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
3-
RestrictedMethods.java:24:27: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
4-
RestrictedMethods.java:33:16: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
1+
RestrictedMethods.java:15:44: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
2+
RestrictedMethods.java:19:49: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
3+
RestrictedMethods.java:25:27: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
4+
RestrictedMethods.java:34:16: compiler.warn.restricted.method: java.lang.foreign.MemorySegment, reinterpret(long)
55
- compiler.err.warnings.and.werror
66
1 error
77
4 warnings

0 commit comments

Comments
 (0)