Null-Safety on Steroids
One of the major features in Eclipse Juno is the improved null-analysis in the Java Development Tools (JDT). At first it sounds really amazing: You just put a few annotations into your code and the compiler will tell you up-front when you try to access a null value. NullPointerExceptions are history, aren't they?
In this session I want to outline the pros and cons of the approach that was implemented by the Eclipse JDT. I will demonstrate how powerful the NPE detection is and outline the advantages of the type annotations which are part of Java8 when it comes to static analysis. Furthermore I will talk about the limits of static analysis when it comes to multi project setups, framework development and working with existing code bases.
To circumvent this limitation, I implemented a small compiler extension that combines the static analysis of the JDT with pragmatic runtime assertions. These assertions close the gap between the static and dynamic nature of Java programs and greatly simplify the live of us Java developers. The plug-in follows a few principles:
* Interfaces define a contract: All implementations should be validated against that contract.
* Don't impose restrictions on the used annotations. Being it Findbugs, (the dormant) JSR 305 or JDTs annotation library: All of these should work seamlessly together.
* Fail early! A meaningful exception can save us from hours of debugging.
If you want to learn more about static and runtime NPE prevention, this session is right for you.