JDK-8280743 : HSDB "Monitor Cache Dump" command might throw NPE
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc-agent
  • Affected Version: 18,19
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-01-26
  • Updated: 2023-08-28
  • Resolved: 2023-08-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b12Fixed
Related Reports
Relates :  
Relates :  
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.
Comments
Changeset: 2c60cadf Author: Chris Plummer <cjplummer@openjdk.org> Date: 2023-08-23 19:12:35 +0000 URL: https://git.openjdk.org/jdk/commit/2c60cadfde61363d1f5aefdcf138e039a461c914
23-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15369 Date: 2023-08-21 19:54:59 +0000
21-08-2023