diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java b/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java index 20ec1b00bac..3509f35a1c5 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java @@ -95,7 +95,7 @@ public final class StatementSwitchToExpressionSwitch extends BugChecker ImmutableSet.of(THROW, EXPRESSION_STATEMENT); private static final ImmutableSet KINDS_RETURN_OR_THROW = ImmutableSet.of(THROW, RETURN); private static final Pattern FALL_THROUGH_PATTERN = - Pattern.compile("\\bfalls?.?through\\b", Pattern.CASE_INSENSITIVE); + Pattern.compile("\\bfalls?.?(through|out)\\b", Pattern.CASE_INSENSITIVE); // Default (negative) result for assignment switch conversion analysis. Note that the value is // immutable. private static final AssignmentSwitchAnalysisResult DEFAULT_ASSIGNMENT_SWITCH_ANALYSIS_RESULT = diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java index 92e3c2bb662..7cac131bb20 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java @@ -4705,4 +4705,42 @@ String f(int x) { "-XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true") .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); } + + @Test + public void fallOutComment() { + refactoringHelper + .addInputLines( + "Test.java", + """ + public class Test { + String f(int x) { + switch (x) { + case 0: + return "ZERO"; + default: // fall out + } + return ""; + } + } + """) + .addOutputLines( + "Test.java", + """ + public class Test { + String f(int x) { + switch (x) { + case 0 -> { + return "ZERO"; + } + default -> {} + } + return ""; + } + } + """) + .setArgs( + "-XepOpt:StatementSwitchToExpressionSwitch:EnableDirectConversion=true", + "-XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true") + .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); + } }