Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8060483

NPE with explicitCastArguments unboxing null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 9
    • 8u40, 9
    • core-libs
    • None
    • b37
    • generic
    • generic
    • Verified

        package jdk.nashorn.test.models;

        import java.lang.invoke.MethodHandle;
        import java.lang.invoke.MethodHandles;
        import java.lang.invoke.MethodType;

        public class NullProvider {
            public static Boolean getBoolean() { return null; }

            public static void main(String[] args) throws Throwable {
                MethodHandle mh = MethodHandles.lookup().findStatic(NullProvider.class, "getBoolean", MethodType.methodType(Boolean.class));
                mh = MethodHandles.explicitCastArguments(mh, MethodType.methodType(boolean.class));
                System.out.println(mh.invoke());
            }
        }

        throws:

        Exception in thread "main" java.lang.NullPointerException
        at sun.invoke.util.ValueConversions.unboxBoolean(ValueConversions.java:95)
        at jdk.nashorn.test.models.NullProvider.main(NullProvider.java:13)

        Expected result would be printing "false", as per documentation for explicitCastArgument that says "If T0 is a reference and T1 a primitive, and if the reference is null at runtime, a zero value is introduced."

        This happens with 9 builds (e.g. just reproduced it with 9 b34). 8 builds (e.g. recent 8u40 early access release builds) seem to behave okay.

              vlivanov Vladimir Ivanov
              attila Attila Szegedi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: