Bug 575030 - [17] [codegen] stackmap generation error switching on
String but expected as pattern

Change-Id: Ieaf1661381cd92504d9fc741689fd6552270b3c2
Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183363
Tested-by: JDT Bot <jdt-bot@eclipse.org>
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 2978ca3..06e2f88 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
@@ -2281,4 +2281,22 @@
 			"The method Zork() is undefined for the type X\n" +
 			"----------\n");
 	}
+	public void testBug575030_01() {
+		this.runConformTest(
+				new String[] {
+					"X.java",
+					"public class X {\n"+
+					" public static void main(String[] args) {\n"+
+					"   foo(\"Hello World!\");\n"+
+					" }\n"+
+					"\n"+
+					" private static void foo(String o) {\n"+
+					"   switch (o) {\n"+
+					"     case String s -> System.out.println(s);\n"+
+					"   }\n"+
+					" }\n"+
+					"}",
+				},
+				"Hello World!");
+	}
 }
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 0f2096c..c404d45 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
@@ -447,7 +447,7 @@
 	 */
 	@Override
 	public void generateCode(BlockScope currentScope, CodeStream codeStream) {
-		if (this.expression.resolvedType.id == TypeIds.T_JavaLangString) {
+		if (this.expression.resolvedType.id == TypeIds.T_JavaLangString && !this.isNonTraditional) {
 			generateCodeForStringSwitch(currentScope, codeStream);
 			return;
 		}
@@ -759,6 +759,11 @@
 						this.expression.computeConversion(upperScope, TypeBinding.INT, expressionType);
 						break checkType;
 					} else if (compilerOptions.complianceLevel >= ClassFileConstants.JDK1_7 && expressionType.id == TypeIds.T_JavaLangString) {
+						if (this.containsPatterns) {
+							isStringSwitch = !JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(compilerOptions);
+							this.isNonTraditional = true;
+							break checkType;
+						}
 						isStringSwitch = true;
 						break checkType;
 					}