Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2019-10-16 00:11:29 -0400
committerSarika Sinha2019-10-16 00:11:29 -0400
commit55f0650606275cab67b539f058d1e4130fba021e (patch)
tree1720e5f2986dd0ac31a41d5d02af38fee9f3f9b3
parentf4cbcd7c1e1db57084adc842fb18deff117a6db4 (diff)
downloadeclipse.jdt.core-55f0650606275cab67b539f058d1e4130fba021e.tar.gz
eclipse.jdt.core-55f0650606275cab67b539f058d1e4130fba021e.tar.xz
eclipse.jdt.core-55f0650606275cab67b539f058d1e4130fba021e.zip
Bug 552107 - [13] Error in JDT Core during AST creation:I20191016-1800
UnsupportedOperationException Change-Id: I2d423328881d9e48e24ecf3f2321c1bfa6cf14ce Signed-off-by: Sarika Sinha <sarika.sinha@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java47
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java2
2 files changed, 48 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
index 21d4e4b092..17592cbbeb 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter13Test.java
@@ -648,4 +648,51 @@ public class ASTConverter13Test extends ConverterTestSetup {
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
+
+ public void test0011() throws CoreException {
+ // saw NPE in SwitchExpression.resolveType(SwitchExpression.java:423)
+ if (!isJRE13) {
+ System.err.println("Test "+getName()+" requires a JRE 13");
+ return;
+ }
+ String source =
+ "public class Switch {\n" +
+ " public static void main(String[] args) {\n" +
+ " foo(Day.TUESDAY);\n" +
+ " }\n" +
+ "\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " private static void foo(Day day) {\n" +
+ " switch (day) {\n" +
+ " case SUNDAY, MONDAY, FRIDAY -> System.out.println(6);\n" +
+ " case TUESDAY -> System.out.println(7);\n" +
+ " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "enum Day {\n" +
+ " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter13/src/Switch.java", true/*resolve*/);
+ IJavaProject javaProject = this.workingCopy.getJavaProject();
+ String old = javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true);
+ try {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.DISABLED);
+ javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ try {
+ buildAST(
+ source,
+ this.workingCopy);
+ } catch(UnsupportedOperationException e) {
+ fail("Should not throw UnsupportedOperationException");
+ } catch(AssertionFailedError e) {
+ e.printStackTrace();
+ return;
+ }
+
+ } finally {
+ javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
+ }
+ }
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index a0f144ad5d..661698f877 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -3219,7 +3219,7 @@ class ASTConverter {
}
public Statement convert(org.eclipse.jdt.internal.compiler.ast.YieldStatement statement) {
- if (this.ast.apiLevel != AST.JLS13_INTERNAL) {
+ if (!this.ast.isPreviewEnabled()) {
return createFakeEmptyStatement(statement);
}
YieldStatement yieldStatement = new YieldStatement(this.ast);

Back to the top