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

NPE with explicitCastArguments unboxing null

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8u40, 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b37
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: