Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FallThrough resilient to missing source information. #1174

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
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;

/** @author cushon@google.com (Liam Miller-Cushon) */
Expand Down Expand Up @@ -63,10 +65,16 @@ 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 caseEndPositionIndex = caseEndPosition(state, caseTree);
int nextStartPositionIndex = next.getStartPosition();
// best effort work-around for https://github.com/google/error-prone/issues/613
if (caseEndPositionIndex == Position.NOPOS || nextStartPositionIndex == Position.NOPOS) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see examples where next.getStartPosition() wasn't available, or just caseEndPosition(state, caseTree) ?

continue;
}
String comments =
state
.getSourceCode()
.subSequence(caseEndPosition(state, caseTree), next.getStartPosition())
.subSequence(caseEndPositionIndex, nextStartPositionIndex)
.toString()
.trim();
if (completes && !FALL_THROUGH_PATTERN.matcher(comments).find()) {
Expand Down