-
Notifications
You must be signed in to change notification settings - Fork 737
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
Avoid NPE in SameNameButDifferent
#1987
Avoid NPE in SameNameButDifferent
#1987
Conversation
Fully skip trees for which the source code is unavailable. While there, also fix what appears to be a typo: "Buiilder" -> "Builder".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some context.
if (state.getEndPosition(tree) != Position.NOPOS) { | ||
treePaths.add(getCurrentPath()); | ||
} | ||
treePaths.add(getCurrentPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped the if
-statement because treeSource != null
implies state.getEndPosition(tree) != Position.NOPOS
.
@@ -96,20 +96,21 @@ private boolean shouldIgnore() { | |||
|
|||
private void handle(Tree tree) { | |||
if (tree instanceof IdentifierTree | |||
&& ((IdentifierTree) tree).getName().contentEquals("Buiilder")) { | |||
&& ((IdentifierTree) tree).getName().contentEquals("Builder")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is what was meant.
With this change the check fully skips trees for which the source code is unavailable. While there, also fix what appears to be a typo: "Buiilder" -> "Builder". Stack trace of the error avoided by this change: ``` [ERROR] /path/to/some/Class.java:[1,1] An unhandled exception was thrown by the Error Prone static analysis plugin. Please report this at https://github.com/google/error-prone/issues/new and include the following: error-prone version: 2.4.1-SNAPSHOT BugPattern: SameNameButDifferent Stack Trace: java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:877) at com.google.common.collect.StandardTable.put(StandardTable.java:145) at com.google.common.collect.HashBasedTable.put(HashBasedTable.java:51) at com.google.errorprone.bugpatterns.SameNameButDifferent$1.handle(SameNameButDifferent.java:108) at com.google.errorprone.bugpatterns.SameNameButDifferent$1.visitMemberSelect(SameNameButDifferent.java:66) at com.google.errorprone.bugpatterns.SameNameButDifferent$1.visitMemberSelect(SameNameButDifferent.java:62) ... snip ... ``` Fixes google#1987 COPYBARA_INTEGRATE_REVIEW=google#1987 from PicnicSupermarket:bugfix/SameNameButDifferent-NPE 3287283 PiperOrigin-RevId: 347736857
With this change the check fully skips trees for which the source code is unavailable.
While there, also fix what appears to be a typo: "Buiilder" -> "Builder".
Stack trace of the error avoided by this change: