Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8246704: --release => \"unknown enum constant PreviewFeature$Feature.…
…TEXT_BLOCKS\"

Use a synthetic annotation instead of inaccessible jdk.internal.PreviewFeature in ct.sym, and avoid resolving that annotation, to prevent errors being printed for the inaccessible types.

Reviewed-by: jlaskey
  • Loading branch information
Jan Lahoda committed Jun 25, 2020
1 parent 42d3bad commit 31c511e6a568132ce83b4ef37949eaa8a50dab8c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
@@ -1067,10 +1067,23 @@ private Annotation[][] createParameterAnnotations(List<CPInfo> constantPool, Lis
}

private Annotation createAnnotation(List<CPInfo> constantPool, AnnotationDescription desc) {
String annotationType = desc.annotationType;

if (PREVIEW_FEATURE_ANNOTATION.equals(annotationType)) {
//the non-public PreviewFeature annotation will not be available in ct.sym,
//replace with purely synthetic javac-internal annotation:
annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
}

return new Annotation(null,
addString(constantPool, desc.annotationType),
addString(constantPool, annotationType),
createElementPairs(constantPool, desc.values));
}
//where:
private static final String PREVIEW_FEATURE_ANNOTATION =
"Ljdk/internal/PreviewFeature;";
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
"Ljdk/internal/PreviewFeature+Annotation;";

private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) {
element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()];
@@ -217,6 +217,7 @@ public static Symtab instance(Context context) {
public final Type elementTypeType;
public final Type functionalInterfaceType;
public final Type previewFeatureType;
public final Type previewFeatureInternalType;
public final Type typeDescriptorType;
public final Type recordType;

@@ -580,6 +581,7 @@ public <R, P> R accept(ElementVisitor<R, P> v, P p) {
stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
previewFeatureType = enterClass("jdk.internal.PreviewFeature");
previewFeatureInternalType = enterSyntheticAnnotation("jdk.internal.PreviewFeature+Annotation");
typeDescriptorType = enterClass("java.lang.invoke.TypeDescriptor");
recordType = enterClass("java.lang.Record");

@@ -1429,6 +1429,9 @@ else if (proxy.type.tsym.flatName() == syms.profileType.tsym.flatName()) {
}
}
}
} else if (proxy.type.tsym.flatName() == syms.previewFeatureInternalType.tsym.flatName()) {
sym.flags_field |= PREVIEW_API;
setFlagIfAttributeTrue(proxy, sym, names.essentialAPI, PREVIEW_ESSENTIAL_API);
} else {
if (proxy.type.tsym == syms.annotationTargetType.tsym) {
target = proxy;
@@ -0,0 +1,15 @@
/**
* @test /nodynamiccopyright/
* @bug 8246704
* @summary Verify preview APIs are reported correctly when using --release.
* @compile/fail/ref=PreviewAPIsWithRelease.out -XDrawDiagnostics --release 14 PreviewAPIsWithRelease.java
*/

import com.sun.source.tree.Tree.Kind;

public class PreviewAPIsWithRelease {
void test() {
"".stripIndent();
Kind r = Kind.RECORD;
}
}
@@ -0,0 +1,4 @@
PreviewAPIsWithRelease.java:12:11: compiler.err.is.preview: stripIndent()
PreviewAPIsWithRelease.java:13:22: compiler.warn.is.preview: RECORD
1 error
1 warning

0 comments on commit 31c511e

Please sign in to comment.