This snippet throws an NullPointerException
due to the fact that its unboxed to a primitive type and Long.longValue()
is called, right?
Tha
That's not what IllegalArgumentException
means. The compiler has no guarantee that the value will be null
until runtime. All it knows is the type, which in your example is likely to be String
.
Certainly at runtime, when the exception is thrown, the compiler knows that the problem is a null
value. You can see this yourself if you're using a debugger. So from a technology standpoint -- and here is the short answer to your question -- yes, it would be possible to create a compiler that will include that in the error description. But if you want a special message for null
values, what's next? Special messages for integers that are outside some acceptable bound by more than 10? Admittedly that's kind of a silly example, but I hope it's illustrative.