mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
7071246: Enclosing string literal in parenthesis in switch-case crashes javac
Reviewed-by: mcimadamore
This commit is contained in:
parent
53abe0d254
commit
dba9612ad9
2 changed files with 21 additions and 4 deletions
|
@ -3450,6 +3450,7 @@ public class Lower extends TreeTranslator {
|
||||||
JCExpression expression = oneCase.getExpression();
|
JCExpression expression = oneCase.getExpression();
|
||||||
|
|
||||||
if (expression != null) { // expression for a "default" case is null
|
if (expression != null) { // expression for a "default" case is null
|
||||||
|
expression = TreeInfo.skipParens(expression);
|
||||||
String labelExpr = (String) expression.type.constValue();
|
String labelExpr = (String) expression.type.constValue();
|
||||||
Integer mapping = caseLabelToPosition.put(labelExpr, casePosition);
|
Integer mapping = caseLabelToPosition.put(labelExpr, casePosition);
|
||||||
Assert.checkNull(mapping);
|
Assert.checkNull(mapping);
|
||||||
|
@ -3555,8 +3556,8 @@ public class Lower extends TreeTranslator {
|
||||||
if (isDefault)
|
if (isDefault)
|
||||||
caseExpr = null;
|
caseExpr = null;
|
||||||
else {
|
else {
|
||||||
caseExpr = make.Literal(caseLabelToPosition.get((String)oneCase.
|
caseExpr = make.Literal(caseLabelToPosition.get((String)TreeInfo.skipParens(oneCase.
|
||||||
getExpression().
|
getExpression()).
|
||||||
type.constValue()));
|
type.constValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6827009
|
* @bug 6827009 7071246
|
||||||
* @summary Positive tests for strings in switch.
|
* @summary Positive tests for strings in switch.
|
||||||
* @author Joseph D. Darcy
|
* @author Joseph D. Darcy
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +36,7 @@ public class StringSwitches {
|
||||||
failures += testPileup();
|
failures += testPileup();
|
||||||
failures += testSwitchingTwoWays();
|
failures += testSwitchingTwoWays();
|
||||||
failures += testNamedBreak();
|
failures += testNamedBreak();
|
||||||
|
failures += testExtraParens();
|
||||||
|
|
||||||
if (failures > 0) {
|
if (failures > 0) {
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
@ -260,4 +261,19 @@ public class StringSwitches {
|
||||||
result |= (1<<5);
|
result |= (1<<5);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int testExtraParens() {
|
||||||
|
int failures = 1;
|
||||||
|
String s = "first";
|
||||||
|
|
||||||
|
switch(s) {
|
||||||
|
case (("first")):
|
||||||
|
failures = 0;
|
||||||
|
break;
|
||||||
|
case ("second"):
|
||||||
|
throw new RuntimeException("Should not be reached.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return failures;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue