-
Notifications
You must be signed in to change notification settings - Fork 1
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
Dynamic NPE cases #9
Comments
Agreed with you about comparision with null (#10). Absolutely, there is cases with NPE due to non-initialised fields, or non existing keys in map, but I did see this statistics, and it's pretty hard to implement dynamic npe analysis. I think, we can avoid many cases of dynamic NPE by other ways: use only final fields, every check map for existing or not keys and so on. Good idea for new static analysis. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on approach taken in
nullfree/lib/src/main/java/com/nikialeksey/nullfree/sources/java/JavaSourceFile.java
Line 63 in d9b270a
I think the famous NPE is happening 10% because of explicit
return null; / x = null;
in various flavours,but 90% due something like
HashMap.get("non-existing-key")
or getters for non-initialised object fields with defaults, e.g.name
in https://www.codebyamir.com/blog/stop-returning-null-in-javaBesides, in the second case, it makes sense to skip/allow
!= null
pattern as comparison doesn't do any harm + it's often unavoidable for an imported library classes you don't controlThe text was updated successfully, but these errors were encountered: