Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2021-07-26 21:35:18 -0400
committerManoj Palat2021-07-26 23:18:53 -0400
commit0de458d966e8d120791750e28f79f6abda2b7545 (patch)
tree26581520b7dcb35d9b79035392f528cb2a94b1d0
parentb50ea4c4afc991bdc582f04c1b99ab34c87abf9b (diff)
downloadeclipse.jdt.core-Y20210727-0800.tar.gz
eclipse.jdt.core-Y20210727-0800.tar.xz
eclipse.jdt.core-Y20210727-0800.zip
Bug 574614 - [17] switch codegen - max stack size exceeded - verifyY20210727-0800
error Change-Id: Ic0e31923c8b1d941c2ed179fc2e25568704cc26d Signed-off-by: Manoj Palat <manpalat@in.ibm.com> Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183394 Tested-by: JDT Bot <jdt-bot@eclipse.org>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java55
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java5
2 files changed, 56 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
index 06e2f88eb3..95b826c859 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
@@ -2299,4 +2299,57 @@ public class SwitchPatternTest extends AbstractRegressionTest9 {
},
"Hello World!");
}
-}
+ public void testBug574614_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Long.valueOf(10));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " String s1 = \" Hello \";\n"+
+ " String s2 = \"World!\";\n"+
+ " switch (o) {\n"+
+ " case Integer I && I > 10: break;\n"+
+ " case X J: break;\n"+
+ " case String s : break;\n"+
+ " default:\n"+
+ " s1 = new StringBuilder(String.valueOf(s1)).append(String.valueOf(s2)).toString();\n"+
+ " System.out.println(s1);\n"+
+ " break; \n"+
+ " }\n"+
+ " }\n"+
+ "}",
+ },
+ "Hello World!");
+ }
+ public void testBug574614_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " foo(Long.valueOf(0));\n"+
+ " }\n"+
+ " private static void foo(Object o) {\n"+
+ " switch (o) {\n"+
+ " case Integer I:\n"+
+ " break;\n"+
+ " case String s :\n"+
+ " break;\n"+
+ " case X J:\n"+
+ " break;\n"+
+ " default:\n"+
+ " String s1 = \"Hello \";\n"+
+ " String s2 = \"World!\";\n"+
+ " s1 = s1 +s2; \n"+
+ " System.out.println(s1);\n"+
+ " break;\n"+
+ " }\n"+
+ " } \n"+
+ "}",
+ },
+ "Hello World!");
+ }
+} \ 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 c404d45188..690deb3ba9 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
@@ -657,10 +657,9 @@ public class SwitchStatement extends Expression {
codeStream.load(this.dispatchPatternCopy);
codeStream.load(this.restartIndexLocal);
int invokeDynamicNumber = codeStream.classFile.recordBootstrapMethod(this);
- //TODO: replace this POC code with properly defined constants
codeStream.invokeDynamic(invokeDynamicNumber,
- this.caseLabelElements.size(),
- 1,
+ 2, // Object, restartIndex
+ 1, // int
"typeSwitch".toCharArray(), //$NON-NLS-1$
"(Ljava/lang/Object;I)I".toCharArray(), //$NON-NLS-1$
TypeIds.T_int,

Back to the top