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

Avoid NPE in SameNameButDifferent #1987

Conversation

Stephan202
Copy link
Contributor

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 ...

Fully skip trees for which the source code is unavailable.

While there, also fix what appears to be a typo: "Buiilder" ->
"Builder".
@google-cla google-cla bot added the cla: yes label Dec 6, 2020
Copy link
Contributor Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Some context.

Comment on lines -110 to +113
if (state.getEndPosition(tree) != Position.NOPOS) {
treePaths.add(getCurrentPath());
}
treePaths.add(getCurrentPath());
Copy link
Contributor Author

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")) {
Copy link
Contributor Author

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.

@Stephan202 Stephan202 deleted the bugfix/SameNameButDifferent-NPE branch December 16, 2020 07:33
stevie400 pushed a commit to HubSpot/error-prone that referenced this pull request Jan 15, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants