From 20473c3f9e9341063045de6628d2832694515eb2 Mon Sep 17 00:00:00 2001 From: Lazaro Clapp Date: Wed, 13 May 2020 11:57:25 -0700 Subject: [PATCH] Minor fix to FallThrough to skip generated/mutated AST nodes (e.g. Lombok) Fixes #1573 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=311375182 --- .../google/errorprone/bugpatterns/FallThrough.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/FallThrough.java b/core/src/main/java/com/google/errorprone/bugpatterns/FallThrough.java index 4967aa53e23..b9d5354db1b 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/FallThrough.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/FallThrough.java @@ -31,6 +31,7 @@ import com.sun.source.tree.BlockTree; import com.sun.source.tree.SwitchTree; import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.util.Position; import java.util.regex.Pattern; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -61,12 +62,12 @@ public Description matchSwitch(SwitchTree tree, VisitorState state) { // reported an error if that statement wasn't reachable, and the answer is // independent of any preceding statements. boolean completes = Reachability.canCompleteNormally(getLast(caseTree.stats)); + int endPos = caseEndPosition(state, caseTree); + if (endPos == Position.NOPOS) { + break; + } String comments = - state - .getSourceCode() - .subSequence(caseEndPosition(state, caseTree), next.getStartPosition()) - .toString() - .trim(); + state.getSourceCode().subSequence(endPos, next.getStartPosition()).toString().trim(); if (completes && !FALL_THROUGH_PATTERN.matcher(comments).find()) { state.reportMatch( buildDescription(next)