JDK-7038860 : MethodType.methodType(Class rtype, Class[] ptypes) doesn't throw NPE if ptypes is null
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2011-04-22
  • Updated: 2012-03-22
  • Resolved: 2011-05-14
Related Reports
Duplicate :  
Relates :  
Description
Please see the minimized test below to reproduce the issue.

Minimized test:
===============
$ cat Test.java
import java.lang.invoke.*;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) throws Exception {
        Object[][] data = new Object[][] { 
            { (Class) null, (Class[]) null },
            { (Class) null, new Class[]{Object.class} },
            { Object.class, new Class[]{ null} },
            { Object.class, new Class[]{Object.class, (Class) null} },
            { Object.class, (Class[]) null }
        };

        for (int i = 0; i < data.length; i++) {
            Class<?> rtype = (Class) data[i][0];
            Class<?>[] ptypes = (Class[]) data[i][1]; 
            try {
                MethodType.methodType(rtype, ptypes);
                System.out.println("FAILED: NPE not thrown for " + rtype + ", " + Arrays.toString(ptypes));
            } catch(NullPointerException ok) {
                System.out.println("OK: NPE is thrown for " + rtype + ", " + Arrays.toString(ptypes));
            }
        }
    }
}

Minimized test output:
========================

$ javac Test.java
$ java -showversion -verify Test
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b138)
Java HotSpot(TM) Server VM (build 21.0-b08, mixed mode)

OK: NPE is thrown for null, null
OK: NPE is thrown for null, [class java.lang.Object]
OK: NPE is thrown for class java.lang.Object, [null]
OK: NPE is thrown for class java.lang.Object, [class java.lang.Object, null]
FAILED: NPE not thrown for class java.lang.Object, null

Comments
EVALUATION Correct. The MethodType.makeImpl allows null explicitly, which is a mistake. Can be easily changed to elicit the correct NPE.
13-05-2011