Skip to content

Commit

Permalink
StatementSwitchToExpressionSwitch: handle empty statement blocks
Browse files Browse the repository at this point in the history
Fixes #3638.
  • Loading branch information
Stephan202 committed Dec 31, 2022
1 parent 721096f commit 773f647
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static AnalysisResult analyzeSwitchTree(SwitchTree switchTree) {

List<? extends StatementTree> statements = caseTree.getStatements();
CaseFallThru caseFallThru = CaseFallThru.MAYBE_FALLS_THRU;
if (statements.isEmpty()) {
if (statements == null || statements.isEmpty()) {
// If the code for this case is just an empty block, then it must fall thru
caseFallThru = CaseFallThru.DEFINITELY_DOES_FALL_THRU;
// Can group with the next case (unless this is the last case)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,23 @@ public void singleCaseConvertible_error() {
.doTest();
}

@Test
public void emptySwitchCases_noMatch() {
assumeTrue(RuntimeVersion.isAtLeast14());
helper
.addSourceLines(
"Test.java",
"class Test {",
" void foo(int value) { ",
" switch (value) {",
" case 0 -> {}",
" default -> {}",
" }",
" }",
"}")
.doTest();
}

@Test
public void dynamicWithThrowableDuringInitializationFromMethod_noMatch() {
assumeTrue(RuntimeVersion.isAtLeast14());
Expand Down

0 comments on commit 773f647

Please sign in to comment.