Handle the "billion-dollar mistake" in Java: help tools understand your code

Status:
Accepted

I'm sure you've already been thinking:

"heck! Javadoc is a weak way of expressing the fact I'm *not* accepting a null parameter there".

And then writing this typical cumbersome kind of code:

void pleaseWaste(My time) {
    if (time == null) {
        throw new IllegalArgumentException("are you kidding?");
    }
    System.out.printf("It is %s\n", time.asUserReadable() );
}

What if you could't write instead:

void pleaseWaste(@NonNull My time) {
    System.out.printf("It is %s\n", time.asUserReadable() );
}

And the caller simply be warned when passing a null value to that method during development?

Since Juno, you can enable the so-called Null Analysis.

Behind that apparently complicated name actually lies a simple and powerful feature
for the day-to-day developer work.

In this session, I'll explain how to use that feature inside Eclipse to improve your code robustness.

We'll also quickly present some tools that may or are already using that metadata to improve their analysis (e.g. SonarQube).

I'll finally cover the inherent advantages and the caveats, from the point of view of a mere developer, not a compiler writer.

Slides

Session details
Speaker(s): Session Type: Experience level:
Beginner
Track: Tags:
JDT
Schedule info
Session Time Slot(s):
Cassiopée - Thursday, June 19, 2014 - 14:40 to 15:15