You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for (NullLiteralExprnullLiteralExpr : StaticJavaParser.parse(stream).findAll(NullLiteralExpr.class)) {
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-java
Besides, 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 control
The text was updated successfully, but these errors were encountered:
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.
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: