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

HSDB "Monitor Cache Dump" command might throw NPE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 22
    • 18, 19
    • hotspot
    • b12

      JDK-8280555 documents a test bug when using ObjectSynchronizer to iterate over all ObjectMonitors. The test code was not protecting against mon.object() being null, and was getting an NPE. While looking for other users of ObjectSynchronizer, I found it is used by the HSDB "Monitor Cache Dump" feature. It has a similar bug that can result in an NPE. The code doing the iterating is:

          ObjectMonitor mon;
          while (i.hasNext()) {
            mon = (ObjectMonitor)i.next();
            if (mon.contentions() != 0 || mon.waiters() != 0 || mon.owner() != null) {
              OopHandle object = mon.object();
              if (object == null) {
                dumpMonitor(tty, mon, true);
              } else {
                dumpMonitor(tty, mon, false);
              }
            }
          }

      So not only can mon.object() be null, but the code is also checking for it. However, dumpMonitor() is not handling it right. It executes the following code unconditionally:

          OopHandle obj = mon.object();
          Oop oop = heap.newOop(obj);
          tty.println(" _object: " + obj + ", a " + oop.getKlass().getName().asString());

      This code will NPE if mon.object() is NULL.

            cjplummer Chris Plummer
            cjplummer Chris Plummer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: