question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: make `ASTHelpers#getSymbol(MethodInvocationTree)` throw rather than return `null`

See original GitHub issue

Currently, ASTHelpers#getSymbol(MethodInvocationTree) can return null if there are errors in the AST:

https://github.com/google/error-prone/blob/eda1c1456d48cb2bef38c99b5a69d4eadbe2af1f/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java#L311-L320

But does Error Prone even run when there are AST errors? If not, it would be helpful for nullability checking if this method just threw an (unchecked) exception in this case rather than returning null. I am working on running NullAway on itself (https://github.com/uber/NullAway/pull/560), and one of the most common “fixes” I had to do was to add castToNonNull around calls to ASTHelpers.getSymbol(MethodInvocationTree) because we have just been assuming it will never return null (and have never observed a case I know of where it did so).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cushoncommented, Jan 25, 2022

I think this is worth revisiting and will be interested to see what Chris’ testing turns up.

But does Error Prone even run when there are AST errors?

It isn’t supposed to, the relevant logic is here: https://github.com/google/error-prone/blob/2fc829ec53beb33d212b977c4f96f29d3ac0eaa7/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java#L119-L121

The other thing we’ll want to watch out for here is that we run Error Prone in a couple of environments where the compilation class path has been ‘optimized’ using heuristics to make it shorter. Sometimes having Error Prone try to handle missing symbols allows reporting some diagnostics when there’s missing information, especially if javac doesn’t need to load those symbols itself.

0reactions
cpovirkcommented, Jan 24, 2022

Thanks. My in-progress test includes the MemberReferenceTree overload, which I’d noticed, but not the NewClassTree one, which I had not. Depending on how that goes, I’ll see about adding NewClassTree or giving up entirely 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should a retrieval method return 'null' or throw an exception ...
The exception would mean that there was a problem. If the value can be missing or present and both are valid for the...
Read more >
[API Proposal]: Throw helpers should return the valid value ...
By making it so that the exception validation helpers always returned the value on exit (instead of being void methods.
Read more >
java - Should security restrictions cause a service to return null ...
String.substring() throws an IndexOutOfBoundsException if the index is out of bounds. I can't think of any advantages to returning null instead ...
Read more >
Java 7 - Null-ignore invocation - Stephen Colebourne's blog
If the expression type is a primitive then zero or false is returned instead of null. If the expression is a void, then...
Read more >
How to Handle the ArgumentNullException in C# | Rollbar
set () functions that checked whether or not the passed argument value was null. If true, we throw in a new System.ArgumentNullException instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found