> One result
of that analysis that strikes me most is that NullPointerExceptions are
the #1 root cause of all error reports.
Did you look into those a little bit
closer? Is the majority of them really caused by 'null' passed into an
API method? From my experience most issues are caused by fields that become
'null' and are later unexpectedly accessed. And a lot of additional NPEs
happen in internal code. Hence just protecting API methods will not be
enough to really get more safety.
No, I did not inspect the ~3200 source code locations where a NullPointerException occurred systematically.
I follow all bug reports and discussions created from error reports and generalized that with my gut feeling.
I agree with you that null fields and internal APIs may make a significant share here. The more null annotations we get the better we are off. If the compiler settings do „normal“ null analysis we may catch a few of those as well. It’s a start.
For projects like Platform and JDT it
is simply not feasible to add those annotations to existing code, even
if only restricted to API methods.
I had feared that :-) How about simply running JDT null analysis on every source method and let the compiler infer the possible values for parameters and method return values? The results of this then could be fed back to the compiler as external null annotations. It wouldn’t be perfect but a start…
I’ve raised a bug about this some time ago. Stephan was interested - but as always: It’s a matter of time.
Note that there is still work in progress
in our Null Analysis Tooling, most important being the support to have
null annotation descriptions for libraries like those from a JRE.
See the comment above.
I’m also fine with adding tool support for crowd-sourcing null annotations. But I’m just not sure whether this would get enough traction to make it worth the efforts...
Having said that, I'm not against encouraging
projects to use null annotations. I we do so, we also have to encourage
them to move to Java 8 to make use of Annotations on Java Types (JSR 308).
Many projects will upgrade to Java 8 anyways since the platform made that move.But IMHO it needs more than a „lip service“ to get this started. So, how could we start? Is Platform (or parts of it like JFace Databinding) leading the way, blogging about it and encouraging people? Do we enable it by default in RCP and Committer package to get developers used to it? Do we have or get resources to run the JDT null analysis on source code and see how far we get with this?