JDK-7032836 : MethodHandle.invokeGeneric throws NPE for null instead of primitive type
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2011-03-31
  • Updated: 2012-03-22
  • Resolved: 2011-05-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Relates :  
Description
Please see the following code:
------------------------------------------------------
import java.dyn.*;
public class Test {
    public static void foo(int i){}
    public static void main(String argv[]) throws Throwable {
        MethodHandle handle = MethodHandles.lookup().findStatic
            (Test.class, "foo", MethodType.methodType(void.class, int.class));
        handle.invokeGeneric(null);
    }
}
------------------------------------------------------
Its output is:
Exception in thread "main" java.lang.NullPointerException
        at sun.dyn.FromGeneric$A4.invoke_I4(FromGeneric.java:552)
        at sun.dyn.FilterGeneric$F3.invoke_F2(FilterGeneric.java:573)
        at Test.main(Test.java:7)

Comments
EVALUATION This behavior is correct. The conversion of the null argument to the int parameter 'i' requires a cast followed by an unbox. The unbox generates the NPE. Any non-null, non-number value will case a ClassCastException. The documentation should make this more clear. The EG has been discussing this issue.
13-05-2011