changeset 49695:d6cbfe9e3030 switch

Avoiding crash in ArgumentAttr when a break inside a switch expression is not a value break.
author jlahoda
date Fri, 23 Mar 2018 14:04:22 +0100
parents 956d81c32894
children f7a8524a7e9b
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out
diffstat 3 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java	Thu Mar 15 22:07:48 2018 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java	Fri Mar 23 14:04:22 2018 +0100
@@ -506,7 +506,8 @@
                 new SwitchExpressionScanner() {
                     @Override
                     public void visitBreak(JCBreak tree) {
-                        buf.add(tree);
+                        if (tree.target == speculativeTree)
+                            buf.add(tree);
                     }
                 }.scan(speculativeTree.cases);
                 res = buf.toList();
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java	Thu Mar 15 22:07:48 2018 +0100
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java	Fri Mar 23 14:04:22 2018 +0100
@@ -61,6 +61,12 @@
                 break "1" + undef; //error: complex value and no switch expression
         }
         }
+        j: print(switch (i) {
+            default: break j;
+        }, 0);
+        j2: print(switch (i) {
+            default: break j2;
+        }, 0);
         return null;
     }
 
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out	Thu Mar 15 22:07:48 2018 +0100
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out	Fri Mar 23 14:04:22 2018 +0100
@@ -8,4 +8,6 @@
 ExpressionSwitchBreaks2.java:55:37: compiler.err.break.ambiguous.target: x
 ExpressionSwitchBreaks2.java:61:17: compiler.err.break.complex.value.no.switch.expression
 ExpressionSwitchBreaks2.java:61:29: compiler.err.cant.resolve.location: kindname.variable, undef, , , (compiler.misc.location: kindname.class, ExpressionSwitchBreaks2, null)
-10 errors
+ExpressionSwitchBreaks2.java:65:22: compiler.err.break.ambiguous.target: j
+ExpressionSwitchBreaks2.java:68:22: compiler.err.break.outside.switch.expression
+12 errors