Repository navigation
Conversation
|
Thanks for the contribution, this looks fine to me. I will pull it in as an internal commit, then it should get pushed back out to Github tomorrow. |
|
How complete a fix is this? Adding synthetic AST nodes isn't a supported part of the plugin API. Is ParameterName the only check it causes problems for, or is it just the first one that crashes? |
|
Not sure how complete it is. I think the key thing the ParameterName check does is call |
check Fixes google#1135 RELNOTES: none ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217574120
|
With this fix and the following update to FallThrough, we're able to compile some large projects which are using Lombok with the error-prone compiler (without any exclusions): 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 843756e42..1bf1d8115 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/FallThrough.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/FallThrough.java
@@ -63,10 +63,17 @@ public class FallThrough extends BugChecker implements SwitchTreeMatcher {
// 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();
+ // check for obviously invalid locations, which can arise, e.g., when a Javac plugin does AST
+ // mutation but doesn't set source locations
+ if (caseEndPositionIndex < 0 || nextStartPositionIndex < 0 || nextStartPositionIndex <= caseEndPositionIndex) {
+ continue;
+ }
String comments =
state
.getSourceCode()
- .subSequence(caseEndPosition(state, caseTree), next.getStartPosition())
+ .subSequence(caseEndPositionIndex, nextStartPositionIndex)
.toString()
.trim();
if (completes && !FALL_THROUGH_PATTERN.matcher(comments).find()) {This would also fix #613. |
check Fixes #1135 RELNOTES: none ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217574120
check Fixes google#1135 RELNOTES: none ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217574120
We've seen a couple of cases where the ParameterName check crashes on method calls that have been inserted into the AST by another tool, e.g., a Javac plugin or Lombok. These additional sanity checks seem to get rid of the crash.
Not obvious how to write a test for this, but open to suggestions.
Fixes #780