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

monitorenter on null object produces unexpected IllegalMonitorStateException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 7, 8, 9, 10
    • hotspot
    • None

      http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2017-May/023453.html

      super class Foo
      version 52:0
      {

      ...
      static Method a:"(Ljava/lang/Object;)V"
      stack 2 locals 3
      {
      aload_0;
      monitorenter;
                      aconst_null;
               monitorenter;
                      aconst_null;
               monitorexit;
      aload_0;
      monitorexit;
      return;
      }

      When calling Foo.a, https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.11.10 says that NullPointerException should be thrown. However, the JDK throws IllegalMonitorStateException:

      ===============
      OUTPUT from JDK8u92:

      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

      Calling Foo.a()
      java.lang.IllegalMonitorStateException
      at Foo.a(Foo.s)
      at A.main(A.java:16)
      Calling Foo.b()
      java.lang.NullPointerException
      at Foo.b(Foo.s)
      at A.main(A.java:22)

        1. Foo.s
          0.6 kB
        2. Foo.class
          0.2 kB
        3. A.java
          1 kB
        4. A.class
          0.7 kB

            dholmes David Holmes
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: