Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9560,33 +9560,31 @@ public void previewAPIUsed(Scope scope, int sourceStart, int sourceEnd, IBinaryA
}
} else
if (CharOperation.equals(valuePair.getName(), ConstantPool.REFLECTIVE)) {
if (valuePair.getValue() instanceof BooleanConstant bool)
isReflective = bool.booleanValue();
if (valuePair.getValue() instanceof BooleanConstant bool)
isReflective = bool.booleanValue();
}
}


String[] arguments = { featureName };
int problemId = -1;
int severity = -1;
if (!this.options.enablePreviewFeatures) {
problemId = IProblem.PreviewAPIDisabled;
severity = isReflective ? ProblemSeverities.Warning : ProblemSeverities.Error;
if (this.options.complianceLevel < ClassFileConstants.getLatestJDKLevel()) {
problemId = IProblem.PreviewAPIUsed;
severity = ProblemSeverities.Warning;
} else {
problemId = IProblem.PreviewAPIDisabled;
severity = isReflective ? ProblemSeverities.Warning : ProblemSeverities.Error;
}
} else {
this.referenceContext.compilationResult().usesPreview = true;
if (this.options.isAnyEnabled(IrritantSet.PREVIEW)) {
severity = ProblemSeverities.Warning;
problemId = IProblem.PreviewAPIUsed;
}
}
if (problemId != -1 && severity != -1)
this.handle(
problemId,
arguments,
arguments,
severity,
sourceStart,
sourceEnd);
if (problemId == -1 || severity == -1) return;
String[] arguments = { featureName };
this.handle(problemId, arguments, arguments, severity, sourceStart, sourceEnd);
}
//Returns true if the problem is handled and reported (only errors considered and not warnings)
private boolean validateRestrictedKeywords(char[] name, int start, int end, boolean reportSyntaxError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PreviewFlagTest extends AbstractRegressionTest9 {
static {
// TESTS_NUMBERS = new int [] { 1 };
// TESTS_RANGE = new int[] { 1, -1 };
// TESTS_NAMES = new String[] { "testIssue3614_001" };
// TESTS_NAMES = new String[] { "testIssue3943_001" };
// TESTS_NAMES = new String[] { "testIssue3614_001" };
}
private String extraLibPath;
Expand Down Expand Up @@ -151,15 +151,21 @@ public static void main(String[] args) {
ScopedValue<Integer> si = ScopedValue.newInstance();
System.out.println(si == null ? "hello" : "world");
}
public int foo() {}
}
"""
},
"----------\n" +
"1. ERROR in X.java (at line 3)\n" +
" ScopedValue<Integer> si = ScopedValue.newInstance();\n" +
" ^^^^^^^^^^^\n" +
"This API is part of the preview feature 'Scoped Values' which is disabled by default. Use --enable-preview to enable\n" +
"----------\n",
"----------\n" +
"1. ERROR in X.java (at line 3)\n" +
" ScopedValue<Integer> si = ScopedValue.newInstance();\n" +
" ^^^^^^^^^^^\n" +
"This API is part of the preview feature 'Scoped Values' which is disabled by default. Use --enable-preview to enable\n" +
"----------\n" +
"2. ERROR in X.java (at line 6)\n" +
" public int foo() {}\n" +
" ^^^^^\n" +
"This method must return a result of type int\n" +
"----------\n",
null,
true,
options);
Expand All @@ -181,12 +187,12 @@ public static void main(String... args) {}
"""
};
runner.expectedCompilerLog =
"----------\n" +
"1. WARNING in X.java (at line 4)\n" +
" return tree.isModule();\n" +
" ^^^^^^^^^^^^^^^\n" +
"This API is part of the preview feature 'Module Import Declarations' which is disabled by default. Use --enable-preview to enable\n" +
"----------\n";
"----------\n" +
"1. WARNING in X.java (at line 4)\n" +
" return tree.isModule();\n" +
" ^^^^^^^^^^^^^^^\n" +
"This API is part of the preview feature 'Module Import Declarations' which is disabled by default. Use --enable-preview to enable\n" +
"----------\n";
runner.runConformTest();
}
public void testIssue3614_003_enabled() throws Exception {
Expand Down Expand Up @@ -218,4 +224,74 @@ public void main(String... args) {
runner.expectedOutputString = "42";
runner.runConformTest();
}
public void testIssue3943_001() throws IOException, ClassFormatException {
Map<String, String> options = getCompilerOptions();
String str = options.get(CompilerOptions.OPTION_Compliance);
options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_23);
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_23);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_23);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
runNegativeTest(new String[] {
"X.java",
"""
public class X {
public static void main(String[] args) {
ScopedValue<Integer> si = ScopedValue.newInstance();
System.out.println(si == null ? "hello" : "world");
}
public int foo() {}
}
"""},
"----------\n" +
"1. WARNING in X.java (at line 3)\n" +
" ScopedValue<Integer> si = ScopedValue.newInstance();\n" +
" ^^^^^^^^^^^\n" +
"You are using an API that is part of the preview feature \'Scoped Values\' and may be removed in future\n" +
"----------\n" +
"2. ERROR in X.java (at line 6)\n" +
" public int foo() {}\n" +
" ^^^^^\n" +
"This method must return a result of type int\n" +
"----------\n",
null,
true,
options);
options.put(CompilerOptions.OPTION_Compliance, str);
options.put(CompilerOptions.OPTION_Source, str);
options.put(CompilerOptions.OPTION_TargetPlatform, str);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
}
public void testIssue3943_002() throws IOException, ClassFormatException {
Map<String, String> options = getCompilerOptions();
String str = options.get(CompilerOptions.OPTION_Compliance);
options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_23);
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_23);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_23);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED);
runNegativeTest(new String[] {
"X.java",
"""
public class X {
@SuppressWarnings("preview")
public static void main(String[] args) {
ScopedValue<Integer> si = ScopedValue.newInstance();
System.out.println(si == null ? "hello" : "world");
}
public int foo() {}
}
"""},
"----------\n" +
"1. ERROR in X.java (at line 7)\n" +
" public int foo() {}\n" +
" ^^^^^\n" +
"This method must return a result of type int\n" +
"----------\n",
null,
true,
options);
options.put(CompilerOptions.OPTION_Compliance, str);
options.put(CompilerOptions.OPTION_Source, str);
options.put(CompilerOptions.OPTION_TargetPlatform, str);
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
}
}
Loading