Proposal: make `ASTHelpers#getSymbol(MethodInvocationTree)` throw rather than return `null`
See original GitHub issueCurrently, ASTHelpers#getSymbol(MethodInvocationTree)
can return null
if there are errors in the AST:
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:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this is worth revisiting and will be interested to see what Chris’ testing turns up.
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.
Thanks. My in-progress test includes the
MemberReferenceTree
overload, which I’d noticed, but not theNewClassTree
one, which I had not. Depending on how that goes, I’ll see about addingNewClassTree
or giving up entirely 😃