Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2019-02-20 09:59:48 +0000
committerManoj Palat2019-02-22 00:33:36 +0000
commitce88cb13b15fbd28376cd9f9cc3207043563910e (patch)
tree3ba7c0019f368bd65ed9598412e1fe5c0ff80de1
parent59bc9a313e66cbc68bf9742a76f5eecef150bdc4 (diff)
downloadeclipse.jdt.core-ce88cb13b15fbd28376cd9f9cc3207043563910e.tar.gz
eclipse.jdt.core-ce88cb13b15fbd28376cd9f9cc3207043563910e.tar.xz
eclipse.jdt.core-ce88cb13b15fbd28376cd9f9cc3207043563910e.zip
Bug 544601 - [12] npe with a switch statement in switch expression
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java31
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java4
2 files changed, 35 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 0e09b494d6..29bc46acfa 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
@@ -2073,4 +2073,35 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
null,
new String[] {"--enable-preview"});
}
+ public void testBug544601_1() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(int i) {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " boolean v = switch (i) {\n" +
+ " case 1:\n" +
+ " switch (i) {\n" +
+ " case 1 : i = 10;\n" +
+ " break;\n" +
+ " default :\n" +
+ " i = 2;\n" +
+ " break;\n" +
+ " }\n" +
+ " break true;\n" +
+ " default: break false;\n" +
+ " };\n" +
+ " return v ? 0 : 1;\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "1",
+ 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 abfd06d9cc..3ab19de9fa 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
@@ -532,6 +532,10 @@ public class SwitchStatement extends Expression {
}
@Override
+ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
+ generateCode(currentScope, codeStream); // redirecting to statement part
+ }
+ @Override
public StringBuffer printStatement(int indent, StringBuffer output) {
printIndent(indent, output).append("switch ("); //$NON-NLS-1$

Back to the top