Integer.intValue()to convert from
Now can you guess what the following code does when you call
public class FB
public void foo()
x = bar();
System.out.println("X is " + x);
public Integer bar()
Yeah, it is throwing a
NullPointerExceptionin the assignment
x = bar()because
nulland the implicit
bar().intValue()is thus throwing the NPE. Without autoboxing, this is much more evident.
Unfortunately it seems like FindBugs and other tools are not (yet) able to detect this (actually in my test code, FindBugs was not even able to detect the NPE in teh explicit call).