I have a method on the current object that takes a parameter. Invoking the method throws a NullPointerException, even though this by definition must not be null.
private String doSomething(int i){
return "I";
}
Invocation:
Integer i = null;
String s = this.doSomething(i);
Why is there a NullPointerException if I’m not referencing a null object?
In this case the JVM internals are throwing a
NullPointerExceptionbecause of the inability to convert aInteger ito theint i. In this case theIntegerisnull, which of course is not valid for the primitive data typeint.This is not a permitted conversion, per the specification, and noted in the guide for Java 1.5.