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

HSDB "Monitor Cache Dump" command might throw NPE

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: 18, 19
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Labels:
      None

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              cjplummer Chris Plummer
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: