Java automatic unboxing - is there a compiler warning?

autoboxing, boxing, java, unboxing

Solution

Eclipse will let you syntax-color boxing and unboxing operations (but not one or the other). I have them set to bright red: if either happens, it means that I've been sloppy in matching parameters and arguments.

Problem

I am a big fan of auto-boxing in Java as it saves a lot of ugly boiler plate code. However I have found auto-unboxing to be confusing in some circumstances where the Number object may be null. Is there any way to detect where auto-unboxing is occurring in a codebase with a javac warning? Any other solution to detect occurrences of unboxing only (such as FindBugs or Eclipse-specific compiler warning) would be appreciated as I cannot find any. To clarify I do not want any warnings to be generated on boxing - only unboxing. Here is a simple example of some code that can cause confusing NullPointerExceptions: ``` class Test { private Integer value; public int getValue() { return value; } } ```

Original source