Skip to content

Commit 7fcd5ca

Browse files
committedJul 7, 2021
8266036: class file for sun.misc.Contended not found
8258421: (jdeprscan) tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java failed with "error: cannot access jdk.internal.ValueBased" Reviewed-by: darcy
1 parent a49b1dc commit 7fcd5ca

File tree

15 files changed

+309
-110
lines changed

15 files changed

+309
-110
lines changed
 

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

+52-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -229,6 +229,7 @@ public void createSymbols(String ctDescriptionFileExtra, String ctDescriptionFil
229229
: null,
230230
Paths.get(ctDescriptionFile));
231231

232+
stripNonExistentAnnotations(data);
232233
splitHeaders(data.classes);
233234

234235
Map<String, Map<Character, String>> package2Version2Module = new HashMap<>();
@@ -301,6 +302,50 @@ public void createSymbols(String ctDescriptionFileExtra, String ctDescriptionFil
301302
}
302303
}
303304

305+
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
306+
"Ljdk/internal/PreviewFeature;";
307+
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
308+
"Ljdk/internal/javac/PreviewFeature;";
309+
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
310+
"Ljdk/internal/PreviewFeature+Annotation;";
311+
private static final String VALUE_BASED_ANNOTATION =
312+
"Ljdk/internal/ValueBased;";
313+
private static final String VALUE_BASED_ANNOTATION_INTERNAL =
314+
"Ljdk/internal/ValueBased+Annotation;";
315+
public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
316+
List.of("Ljdk/Profile+Annotation;",
317+
"Lsun/Proprietary+Annotation;",
318+
PREVIEW_FEATURE_ANNOTATION_OLD,
319+
PREVIEW_FEATURE_ANNOTATION_NEW,
320+
VALUE_BASED_ANNOTATION));
321+
322+
private void stripNonExistentAnnotations(LoadDescriptions data) {
323+
Set<String> allClasses = data.classes.name2Class.keySet();
324+
data.modules.values().forEach(mod -> {
325+
stripNonExistentAnnotations(allClasses, mod.header);
326+
});
327+
data.classes.classes.forEach(clazz -> {
328+
stripNonExistentAnnotations(allClasses, clazz.header);
329+
stripNonExistentAnnotations(allClasses, clazz.fields);
330+
stripNonExistentAnnotations(allClasses, clazz.methods);
331+
});
332+
}
333+
334+
private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
335+
descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
336+
}
337+
338+
private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
339+
stripNonExistentAnnotations(allClasses, d.classAnnotations);
340+
stripNonExistentAnnotations(allClasses, d.runtimeAnnotations);
341+
}
342+
343+
private void stripNonExistentAnnotations(Set<String> allClasses, List<AnnotationDescription> annotations) {
344+
if (annotations != null)
345+
annotations.removeIf(ann -> !HARDCODED_ANNOTATIONS.contains(ann.annotationType) &&
346+
!allClasses.contains(ann.annotationType.substring(1, ann.annotationType.length() - 1)));
347+
}
348+
304349
private ZipEntry createZipEntry(String name, long timestamp) {
305350
ZipEntry ze = new ZipEntry(name);
306351

@@ -1140,17 +1185,16 @@ private Annotation createAnnotation(List<CPInfo> constantPool, AnnotationDescrip
11401185
values.put("reflective", essentialAPI != null && !essentialAPI);
11411186
}
11421187

1188+
if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
1189+
//the non-public ValueBased annotation will not be available in ct.sym,
1190+
//replace with purely synthetic javac-internal annotation:
1191+
annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
1192+
}
1193+
11431194
return new Annotation(null,
11441195
addString(constantPool, annotationType),
11451196
createElementPairs(constantPool, values));
11461197
}
1147-
//where:
1148-
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
1149-
"Ljdk/internal/PreviewFeature;";
1150-
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
1151-
"Ljdk/internal/javac/PreviewFeature;";
1152-
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
1153-
"Ljdk/internal/PreviewFeature+Annotation;";
11541198

11551199
private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) {
11561200
element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()];

‎src/java.base/share/classes/jdk/internal/ValueBased.java

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
* References to <a href="../lang/doc-files/ValueBased.html">value-based classes</a>
3636
* should produce warnings about behavior that is inconsistent with value based semantics.
3737
*
38+
* Note this internal annotation is handled specially by the javac compiler.
39+
* To work properly with {@code --release older-release}, it requires special
40+
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
41+
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
42+
*
3843
* @since 16
3944
*/
4045
@Retention(RetentionPolicy.RUNTIME)

‎src/java.base/share/classes/jdk/internal/javac/NoPreview.java

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
/**
3333
* The element annotated with this annotation should not be marked as a preview element.
34+
*
35+
* Note this internal annotation is handled specially by the javac compiler.
36+
* To work properly with {@code --release older-release}, it requires special
37+
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
38+
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
39+
*
3440
*/
3541
@Target({ElementType.METHOD,
3642
ElementType.CONSTRUCTOR,

‎src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
* Indicates the API declaration in question is associated with a
3232
* <em>preview feature</em>. See JEP 12: "Preview Language and VM
3333
* Features" (http://openjdk.java.net/jeps/12).
34+
*
35+
* Note this internal annotation is handled specially by the javac compiler.
36+
* To work properly with {@code --release older-release}, it requires special
37+
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
38+
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
39+
*
3440
* @since 14
3541
*/
3642
// Match the meaningful targets of java.lang.Deprecated, omit local

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@ public static EnumSet<Flag> asFlagSet(long flags) {
311311
/**
312312
* Flag to indicate the given ModuleSymbol is a system module.
313313
*/
314-
public static final long SYSTEM_MODULE = 1L<<53;
314+
public static final long SYSTEM_MODULE = 1L<<53; //ModuleSymbols only
315+
316+
/**
317+
* Flag to indicate the given ClassSymbol is a value based.
318+
*/
319+
public static final long VALUE_BASED = 1L<<53; //ClassSymbols only
315320

316321
/**
317322
* Flag to indicate the given symbol has a @Deprecated annotation.

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

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public static Symtab instance(Context context) {
222222
public final Type recordType;
223223
public final Type switchBootstrapsType;
224224
public final Type valueBasedType;
225+
public final Type valueBasedInternalType;
225226

226227
/** The symbol representing the length field of an array.
227228
*/
@@ -588,6 +589,7 @@ public <R, P> R accept(ElementVisitor<R, P> v, P p) {
588589
recordType = enterClass("java.lang.Record");
589590
switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");
590591
valueBasedType = enterClass("jdk.internal.ValueBased");
592+
valueBasedInternalType = enterSyntheticAnnotation("jdk.internal.ValueBased+Annotation");
591593

592594
synthesizeEmptyInterfaceIfMissing(autoCloseableType);
593595
synthesizeEmptyInterfaceIfMissing(cloneableType);

‎src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import static com.sun.tools.javac.code.Kinds.Kind.MDL;
5454
import static com.sun.tools.javac.code.Kinds.Kind.MTH;
5555
import static com.sun.tools.javac.code.Kinds.Kind.PCK;
56+
import static com.sun.tools.javac.code.Kinds.Kind.TYP;
5657
import static com.sun.tools.javac.code.Kinds.Kind.VAR;
5758
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
5859
import static com.sun.tools.javac.code.TypeTag.ARRAY;
@@ -369,14 +370,19 @@ private <T extends Attribute.Compound> void annotateNow(Symbol toAnnotate,
369370
}
370371
}
371372

372-
// Note: @Deprecated has no effect on local variables and parameters
373373
if (!c.type.isErroneous()
374374
&& types.isSameType(c.type, syms.previewFeatureType)) {
375375
toAnnotate.flags_field |= Flags.PREVIEW_API;
376376
if (isAttributeTrue(c.member(names.reflective))) {
377377
toAnnotate.flags_field |= Flags.PREVIEW_REFLECTIVE;
378378
}
379379
}
380+
381+
if (!c.type.isErroneous()
382+
&& toAnnotate.kind == TYP
383+
&& types.isSameType(c.type, syms.valueBasedType)) {
384+
toAnnotate.flags_field |= Flags.VALUE_BASED;
385+
}
380386
}
381387

382388
List<T> buf = List.nil();

‎src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -1871,14 +1871,7 @@ public void visitSynchronized(JCSynchronized tree) {
18711871
}
18721872
// where
18731873
private boolean isValueBased(Type t) {
1874-
if (t != null && t.tsym != null) {
1875-
for (Attribute.Compound a: t.tsym.getDeclarationAttributes()) {
1876-
if (a.type.tsym == syms.valueBasedType.tsym) {
1877-
return true;
1878-
}
1879-
}
1880-
}
1881-
return false;
1874+
return t != null && t.tsym != null && (t.tsym.flags() & VALUE_BASED) != 0;
18821875
}
18831876

18841877

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

+5
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,9 @@ else if (proxy.type.tsym.flatName() == syms.profileType.tsym.flatName()) {
14461446
} else if (proxy.type.tsym.flatName() == syms.previewFeatureInternalType.tsym.flatName()) {
14471447
sym.flags_field |= PREVIEW_API;
14481448
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
1449+
} else if (proxy.type.tsym.flatName() == syms.valueBasedInternalType.tsym.flatName()) {
1450+
Assert.check(sym.kind == TYP);
1451+
sym.flags_field |= VALUE_BASED;
14491452
} else {
14501453
if (proxy.type.tsym == syms.annotationTargetType.tsym) {
14511454
target = proxy;
@@ -1457,6 +1460,8 @@ else if (proxy.type.tsym.flatName() == syms.profileType.tsym.flatName()) {
14571460
} else if (proxy.type.tsym == syms.previewFeatureType.tsym) {
14581461
sym.flags_field |= PREVIEW_API;
14591462
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
1463+
} else if (proxy.type.tsym == syms.valueBasedType.tsym && sym.kind == TYP) {
1464+
sym.flags_field |= VALUE_BASED;
14601465
}
14611466
proxies.append(proxy);
14621467
}

‎test/langtools/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,3 @@ tools/sjavac/ClasspathDependencies.java
7272
#
7373
# jdeps
7474

75-
tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java 8258421 generic-all Deprecation vs JDK-private annotation class

‎test/langtools/tools/javac/lint/ExternalAbuseOfVbc.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
22
* @test /nodynamiccopyright/
3-
* @bug 8254274
3+
* @bug 8254274 8258421
44
* @summary lint should warn when an instance of a value based class is synchronized upon
55
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint ExternalAbuseOfVbc.java
66
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:all ExternalAbuseOfVbc.java
77
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
8+
* @compile/fail/ref=ExternalAbuseOfVbc.out --release 16 -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
89
* @compile/ref=LintModeOffAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:-synchronization ExternalAbuseOfVbc.java
910
*/
1011

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ExternalAbuseOfVbc.java:18:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class
1+
ExternalAbuseOfVbc.java:19:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class
22
- compiler.err.warnings.and.werror
33
1 error
44
1 warning
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8266036 8258421
27+
* @summary Verify no error is reported for extended ForkJoinPool with --release 8.
28+
* @modules jdk.compiler
29+
* @build NonPublicAnnotations
30+
* @compile -processor NonPublicAnnotations --release 8 NonPublicAnnotations.java
31+
*/
32+
33+
import java.util.Set;
34+
import java.util.concurrent.ForkJoinPool;
35+
36+
import javax.annotation.processing.AbstractProcessor;
37+
import javax.annotation.processing.RoundEnvironment;
38+
import javax.annotation.processing.SupportedAnnotationTypes;
39+
import javax.lang.model.SourceVersion;
40+
import javax.lang.model.element.TypeElement;
41+
42+
@SupportedAnnotationTypes("*")
43+
public class NonPublicAnnotations extends AbstractProcessor {
44+
45+
@Override
46+
public boolean process(Set<? extends TypeElement> roots, RoundEnvironment roundEnv) {
47+
return false;
48+
}
49+
50+
@Override
51+
public SourceVersion getSupportedSourceVersion() {
52+
return SourceVersion.latestSupported();
53+
}
54+
55+
}
56+
57+
class TestForkJoinPool extends ForkJoinPool {}

‎test/langtools/tools/javac/platform/createsymbols/CreateSymbolsTestImpl.java

+151-81
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -215,82 +215,88 @@ void testConstantTest() throws Exception {
215215

216216
@Test
217217
void testAnnotations() throws Exception {
218-
doPrintElementTest("package t;" +
219-
"import java.lang.annotation.*;" +
220-
"public @Visible @Invisible class T { public void extra() { } }" +
221-
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
222-
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
223-
"package t;" +
224-
"import java.lang.annotation.*;" +
225-
"public @Visible @Invisible class T { }" +
226-
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
227-
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
228-
"t.T",
229-
"package t;\n\n" +
230-
"@t.Invisible\n" +
231-
"@t.Visible\n" +
232-
"public class T {\n\n" +
233-
" public T();\n\n" +
234-
" public void extra();\n" +
235-
"}\n",
236-
"t.Visible",
237-
"package t;\n\n" +
238-
"@java.lang.annotation.Retention(RUNTIME)\n" +
239-
"@interface Visible {\n" +
240-
"}\n");
241-
doPrintElementTest("package t;" +
242-
"import java.lang.annotation.*;" +
243-
"import java.util.*;" +
244-
"public class T {" +
245-
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
246-
"}" +
247-
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
248-
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
249-
"package t;" +
250-
"import java.lang.annotation.*;" +
251-
"import java.util.*;" +
252-
"public class T {" +
253-
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
254-
" public void extra() { }" +
255-
"}" +
256-
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
257-
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
258-
"t.T",
259-
"package t;\n\n" +
260-
"public class T {\n\n" +
261-
" public T();\n\n" +
262-
" public void test(int arg0,\n" +
263-
" @t.Invisible int arg1,\n" +
264-
" @t.Visible java.util.List<java.lang.String> arg2,\n" +
265-
" int arg3);\n" +
266-
"}\n",
267-
"t.Visible",
268-
"package t;\n\n" +
269-
"@java.lang.annotation.Retention(RUNTIME)\n" +
270-
"@interface Visible {\n" +
271-
"}\n");
272-
doPrintElementTest("package t;" +
273-
"import java.lang.annotation.*;" +
274-
"public class T {" +
275-
" public void test(@Ann(v=\"url\", dv=\"\\\"\\\"\") String str) { }" +
276-
"}" +
277-
"@Retention(RetentionPolicy.RUNTIME) @interface Ann {" +
278-
" public String v();" +
279-
" public String dv();" +
280-
"}",
281-
"package t;" +
282-
"public class T { }",
283-
"t.T",
284-
"package t;\n\n" +
285-
"public class T {\n\n" +
286-
" public T();\n\n" +
287-
" public void test(@t.Ann(dv=\"\\\"\\\"\", v=\"url\") java.lang.String arg0);\n" +
288-
"}\n",
289-
"t.T",
290-
"package t;\n\n" +
291-
"public class T {\n\n" +
292-
" public T();\n" +
293-
"}\n");
218+
Set<String> extraAnnotations = Set.of("Ljava/lang/annotation/Retention;");
219+
CreateSymbols.HARDCODED_ANNOTATIONS.addAll(extraAnnotations);
220+
try {
221+
doPrintElementTest("package t;" +
222+
"import java.lang.annotation.*;" +
223+
"public @Visible @Invisible class T { public void extra() { } }" +
224+
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
225+
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
226+
"package t;" +
227+
"import java.lang.annotation.*;" +
228+
"public @Visible @Invisible class T { }" +
229+
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
230+
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
231+
"t.T",
232+
"package t;\n\n" +
233+
"@t.Invisible\n" +
234+
"@t.Visible\n" +
235+
"public class T {\n\n" +
236+
" public T();\n\n" +
237+
" public void extra();\n" +
238+
"}\n",
239+
"t.Visible",
240+
"package t;\n\n" +
241+
"@java.lang.annotation.Retention(RUNTIME)\n" +
242+
"@interface Visible {\n" +
243+
"}\n");
244+
doPrintElementTest("package t;" +
245+
"import java.lang.annotation.*;" +
246+
"import java.util.*;" +
247+
"public class T {" +
248+
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
249+
"}" +
250+
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
251+
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
252+
"package t;" +
253+
"import java.lang.annotation.*;" +
254+
"import java.util.*;" +
255+
"public class T {" +
256+
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
257+
" public void extra() { }" +
258+
"}" +
259+
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
260+
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
261+
"t.T",
262+
"package t;\n\n" +
263+
"public class T {\n\n" +
264+
" public T();\n\n" +
265+
" public void test(int arg0,\n" +
266+
" @t.Invisible int arg1,\n" +
267+
" @t.Visible java.util.List<java.lang.String> arg2,\n" +
268+
" int arg3);\n" +
269+
"}\n",
270+
"t.Visible",
271+
"package t;\n\n" +
272+
"@java.lang.annotation.Retention(RUNTIME)\n" +
273+
"@interface Visible {\n" +
274+
"}\n");
275+
doPrintElementTest("package t;" +
276+
"import java.lang.annotation.*;" +
277+
"public class T {" +
278+
" public void test(@Ann(v=\"url\", dv=\"\\\"\\\"\") String str) { }" +
279+
"}" +
280+
"@Retention(RetentionPolicy.RUNTIME) @interface Ann {" +
281+
" public String v();" +
282+
" public String dv();" +
283+
"}",
284+
"package t;" +
285+
"public class T { }",
286+
"t.T",
287+
"package t;\n\n" +
288+
"public class T {\n\n" +
289+
" public T();\n\n" +
290+
" public void test(@t.Ann(dv=\"\\\"\\\"\", v=\"url\") java.lang.String arg0);\n" +
291+
"}\n",
292+
"t.T",
293+
"package t;\n\n" +
294+
"public class T {\n\n" +
295+
" public T();\n" +
296+
"}\n");
297+
} finally {
298+
CreateSymbols.HARDCODED_ANNOTATIONS.removeAll(extraAnnotations);
299+
}
294300
}
295301

296302
@Test
@@ -360,11 +366,70 @@ void testGenerification() throws Exception {
360366
Expect.SUCCESS);
361367
}
362368

369+
@Test
370+
void testClearMissingAnnotations() throws Exception {
371+
doPrintElementTest(new String[] {
372+
"""
373+
package t;
374+
import t.impl.HC;
375+
import t.impl.HR;
376+
@HC @HR public class T {
377+
@HC @HR public static final int i = 0;
378+
@HC @HR public void t() {}
379+
}
380+
""",
381+
"""
382+
package t.impl;
383+
import java.lang.annotation.*;
384+
@Retention(RetentionPolicy.CLASS)
385+
public @interface HC {
386+
}
387+
""",
388+
"""
389+
package t.impl;
390+
import java.lang.annotation.*;
391+
@Retention(RetentionPolicy.RUNTIME)
392+
public @interface HR {
393+
}
394+
"""
395+
},
396+
new String[] {
397+
"""
398+
package t;
399+
public class T {
400+
public static final int i = 0;
401+
}
402+
"""
403+
},
404+
"t.T",
405+
"""
406+
package t;
407+
408+
public class T {
409+
public static final int i = 0;
410+
411+
public T();
412+
413+
public void t();
414+
}
415+
""",
416+
"t.T",
417+
"""
418+
package t;
419+
420+
public class T {
421+
public static final int i = 0;
422+
423+
public T();
424+
}
425+
""");
426+
}
427+
363428
int i = 0;
364429

365430
void doTest(String code7, String code8, String testCode, Expect result7, Expect result8) throws Exception {
366431
ToolBox tb = new ToolBox();
367-
Path classes = prepareVersionedCTSym(code7, code8);
432+
Path classes = prepareVersionedCTSym(new String[] {code7}, new String[] {code8});
368433
Path output = classes.getParent();
369434
Path scratch = output.resolve("scratch");
370435

@@ -392,6 +457,10 @@ private static String computeClassPath(Path classes, String version) throws IOEx
392457
}
393458

394459
void doPrintElementTest(String code7, String code8, String className7, String printed7, String className8, String printed8) throws Exception {
460+
doPrintElementTest(new String[] {code7}, new String[] {code8}, className7, printed7, className8, printed8);
461+
}
462+
463+
void doPrintElementTest(String[] code7, String[] code8, String className7, String printed7, String className8, String printed8) throws Exception {
395464
ToolBox tb = new ToolBox();
396465
Path classes = prepareVersionedCTSym(code7, code8);
397466
Path output = classes.getParent();
@@ -419,7 +488,7 @@ void doPrintElementTest(String code7, String code8, String className7, String pr
419488
}
420489

421490
void doTestEquivalence(String code7, String code8, String testClass) throws Exception {
422-
Path classes = prepareVersionedCTSym(code7, code8);
491+
Path classes = prepareVersionedCTSym(new String[] {code7}, new String[] {code8});
423492
Path classfile = classes.resolve("78").resolve("java.base").resolve(testClass.replace('.', '/') + ".class");
424493

425494
if (!Files.isReadable(classfile)) {
@@ -576,7 +645,7 @@ void doTestIncluded(String code, String... includedClasses) throws Exception {
576645
boolean oldIncludeAll = includeAll;
577646
try {
578647
includeAll = false;
579-
Path classes = prepareVersionedCTSym(code, "package other; public class Other {}");
648+
Path classes = prepareVersionedCTSym(new String[] {code}, new String[] {"package other; public class Other {}"});
580649
Path root = classes.resolve("7").resolve("java.base");
581650
try (Stream<Path> classFiles = Files.walk(root)) {
582651
Set<String> names = classFiles.map(p -> root.relativize(p))
@@ -595,7 +664,7 @@ void doTestIncluded(String code, String... includedClasses) throws Exception {
595664
}
596665
}
597666

598-
Path prepareVersionedCTSym(String code7, String code8) throws Exception {
667+
Path prepareVersionedCTSym(String[] code7, String[] code8) throws Exception {
599668
String testClasses = System.getProperty("test.classes");
600669
Path output = Paths.get(testClasses, "test-data" + i++);
601670
deleteRecursively(output);
@@ -694,6 +763,7 @@ List<String> collectClassFile(Path root) throws IOException {
694763
return files.filter(p -> Files.isRegularFile(p))
695764
.filter(p -> p.getFileName().toString().endsWith(".class"))
696765
.map(p -> root.relativize(p).toString())
766+
.filter(p -> !p.contains("impl"))
697767
.collect(Collectors.toList());
698768
}
699769
}

‎test/langtools/tools/javac/sym/ElementStructureTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ public class ElementStructureTest {
128128
(byte) 0xB7, (byte) 0x52, (byte) 0x0F, (byte) 0x68
129129
};
130130
static final byte[] hash7 = new byte[] {
131-
(byte) 0x3C, (byte) 0x03, (byte) 0xEA, (byte) 0x4A,
132-
(byte) 0x62, (byte) 0xD2, (byte) 0x18, (byte) 0xE5,
133-
(byte) 0xA5, (byte) 0xC2, (byte) 0xB7, (byte) 0x85,
134-
(byte) 0x90, (byte) 0xFA, (byte) 0x98, (byte) 0xCD
131+
(byte) 0x45, (byte) 0xCA, (byte) 0x83, (byte) 0xCD,
132+
(byte) 0x1A, (byte) 0x68, (byte) 0x57, (byte) 0x9C,
133+
(byte) 0x6F, (byte) 0x2D, (byte) 0xEB, (byte) 0x28,
134+
(byte) 0xAB, (byte) 0x05, (byte) 0x53, (byte) 0x6E
135135
};
136136
static final byte[] hash8 = new byte[] {
137-
(byte) 0x24, (byte) 0x38, (byte) 0x52, (byte) 0x1C,
138-
(byte) 0x5E, (byte) 0x83, (byte) 0x82, (byte) 0xE6,
139-
(byte) 0x41, (byte) 0xC2, (byte) 0xDD, (byte) 0x2A,
140-
(byte) 0xFD, (byte) 0xFF, (byte) 0x5E, (byte) 0x2F
137+
(byte) 0x26, (byte) 0x8C, (byte) 0xFD, (byte) 0x61,
138+
(byte) 0x53, (byte) 0x00, (byte) 0x57, (byte) 0x10,
139+
(byte) 0x36, (byte) 0x2B, (byte) 0x92, (byte) 0x0B,
140+
(byte) 0xE1, (byte) 0x6A, (byte) 0xB5, (byte) 0xFD
141141
};
142142

143143
final static Map<String, byte[]> version2Hash = new HashMap<>();

0 commit comments

Comments
 (0)
Please sign in to comment.