This snippet throws an NullPointerException
due to the fact that its unboxed to a primitive type and Long.longValue()
is called, right?
Thats even easy to see if you have a snippet like this:
long value = (Long) null;
But the NullPointerException
is even harder to get in a more complex situation like this:
long propertyValue = (Long) obj.getProperty(propertyModel.getName());
So isn't there any possibility for the Java-Compiler to make a more comfortable Exception out of this? I would prefer an IllegalArgumentException
with a message like "You're trying to cast a null-Object into a primitive type, this can't be done!"
Wouldn't this be more appropirated? What do you think? Is this even possible at runtime? Are we able to determine this cast? I didn't looked at the java bytecode until yet. Maybe this supports any solution.
This question can be answered: I like to now if its possible to achieve this behaviour!