Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit 23b83c5

Browse files
author
Vicente Romero
committed
8253954: javac crash when compiling code with enhanced switch expressions with option -Xjcov
Reviewed-by: jjg
1 parent 8b37c2c commit 23b83c5

File tree

2 files changed

+45
-0
lines changed
  • src/jdk.compiler/share/classes/com/sun/tools/javac/jvm
  • test/langtools/tools/javac/switchexpr

2 files changed

+45
-0
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ public void visitBreak(JCBreak tree) {
379379

380380
public void visitYield(JCYield tree) {
381381
SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
382+
sr.mergeWith(csp(tree.value));
382383
result = sr;
383384
}
384385

test/langtools/tools/javac/switchexpr/CRT.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,50 @@ private void run() throws Exception {
143143
" 35, 63, 180d, 240a, 10 // 35, 63, 6:13, 9:10, flow-target\n" +
144144
" 0, 64, c09, 240b, 1 // 0, 64, 3:09, 9:11, statement\n" +
145145
" 0, 64, 824, 2806, 2 // 0, 64, 2:36, 10:06, block\n");
146+
doTest(
147+
"""
148+
private boolean convert(int i) {
149+
return switch (i) {
150+
default -> (i < 256) ? true : false;
151+
};
152+
}
153+
""",
154+
"""
155+
CharacterRangeTable:
156+
0, 0, c14, c15, 8 // 0, 0, 3:20, 3:21, flow-controller
157+
12, 15, 1014, 101d, 8 // 12, 15, 4:20, 4:29, flow-controller
158+
16, 18, 1014, 101d, 100 // 16, 18, 4:20, 4:29, branch-false
159+
19, 19, 1020, 1024, 10 // 19, 19, 4:32, 4:36, flow-target
160+
23, 23, 1027, 102c, 10 // 23, 23, 4:39, 4:44, flow-target
161+
12, 26, 1014, 102d, 11 // 12, 26, 4:20, 4:45, statement, flow-target
162+
0, 27, c05, 1407, 1 // 0, 27, 3:05, 5:07, statement
163+
0, 27, 820, 1802, 2 // 0, 27, 2:32, 6:02, block
164+
"""
165+
);
166+
doTest(
167+
"""
168+
private boolean convert(int i) {
169+
return switch (i) {
170+
case 1 -> switch (Integer.toString(i)) {
171+
case "1" -> true;
172+
default -> throw new IllegalStateException("failure");
173+
};
174+
default -> throw new IllegalStateException("failure");
175+
};
176+
}
177+
""",
178+
"""
179+
CharacterRangeTable:
180+
0, 0, c14, c15, 8 // 0, 0, 3:20, 3:21, flow-controller
181+
20, 24, 1013, 102f, 1 // 20, 24, 4:19, 4:47, statement
182+
80, 83, 1419, 141e, 11 // 80, 83, 5:25, 5:30, statement, flow-target
183+
84, 93, 1818, 1843, 11 // 84, 93, 6:24, 6:67, statement, flow-target
184+
20, 96, 1013, 1c0b, 11 // 20, 96, 4:19, 7:11, statement, flow-target
185+
97, 106, 2014, 203f, 11 // 97, 106, 8:20, 8:63, statement, flow-target
186+
0, 107, c05, 2407, 1 // 0, 107, 3:05, 9:07, statement
187+
0, 107, 820, 2802, 2 // 0, 107, 2:32, 10:02, block
188+
"""
189+
);
146190
}
147191

148192
private void doTest(String code, String expected) throws Exception {

0 commit comments

Comments
 (0)