Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2019-03-07 14:39:12 +0000
committerManoj Palat2019-03-07 14:39:12 +0000
commitb18b06a7905221757481afe8da611c6db4ce277b (patch)
tree41d0b8c35756b123332e13ed322b81b80d5cfe75
parentd9dd4c4df7ad218a8571d028ac3719cc0f3a7a95 (diff)
downloadeclipse.jdt.core-b18b06a7905221757481afe8da611c6db4ce277b.tar.gz
eclipse.jdt.core-b18b06a7905221757481afe8da611c6db4ce277b.tar.xz
eclipse.jdt.core-b18b06a7905221757481afe8da611c6db4ce277b.zip
Bug 545168 - [12] NPE in BreakStatement.analyseCode
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java28
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java1
2 files changed, 29 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
index 9dc36ff9ca..b3cf79860e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
@@ -2154,4 +2154,32 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
null,
new String[] {"--enable-preview"});
}
+ public void testBug545168_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " public static void foo(Day day) {\n" +
+ " switch (day) {\n" +
+ " case MONDAY, FRIDAY -> System.out.println(Day.SUNDAY);\n" +
+ " case TUESDAY -> System.out.println(7);\n" +
+ " case THURSDAY, SATURDAY -> System.out.println(8);\n" +
+ " case WEDNESDAY -> System.out.println(9);\n" +
+ " default -> {}\n" +
+ " } \n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " X.foo(Day.WEDNESDAY);\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "enum Day {\n" +
+ " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" +
+ "}\n"
+ },
+ "9",
+ null,
+ new String[] {"--enable-preview"});
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
index 0f49d12bf4..8670e38554 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
@@ -100,6 +100,7 @@ public class SwitchStatement extends Expression {
int l = block.statements == null ? 0 : block.statements.length;
if (l == 0) {
block.statements = new Statement[] {breakStatement};
+ block.scope = this.scope; // (upper scope) see Block.resolve() for similar
} else {
Statement[] newArray = new Statement[l + 1];
System.arraycopy(block.statements, 0, newArray, 0, l);

Back to the top