apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.66k stars 851 forks source link

NPE when parsing STICKY_CLASS tags in hprof heap dump #6357

Open patrickptibco opened 1 year ago

patrickptibco commented 1 year ago

Apache NetBeans version

Apache NetBeans 18

What happened

I was attempting to load a hprof from visualvm 2.1.6 in the netbeans profiler. Instead of loading, it threw an NPE

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.netbeans.lib.profiler.heap.Instance.getInstanceId()" because the return value of "org.netbeans.lib.profiler.heap.GCRoot.getInstance()" is null
    at org.netbeans.lib.profiler.heap.HprofGCRoots.getGCRoot(HprofGCRoots.java:96)
    at org.netbeans.lib.profiler.heap.NearestGCRoot.writeConnection(NearestGCRoot.java:311)
    at org.netbeans.lib.profiler.heap.NearestGCRoot.writeClassConnection(NearestGCRoot.java:294)
    at org.netbeans.lib.profiler.heap.NearestGCRoot.computeOneLevel(NearestGCRoot.java:219)
    at org.netbeans.lib.profiler.heap.NearestGCRoot.computeGCRoots(NearestGCRoot.java:109)
    at org.netbeans.lib.profiler.heap.NearestGCRoot.getLeaves(NearestGCRoot.java:373)
    at org.netbeans.lib.profiler.heap.HprofHeap.computeRetainedSize(HprofHeap.java:704)
    at org.netbeans.lib.profiler.heap.HprofHeap.getBiggestObjectsByRetainedSize(HprofHeap.java:186)

How to reproduce

Minimal code:

package simpletest;

import java.io.File;
import org.netbeans.lib.profiler.heap.HeapFactory;

public class Test {
  public static void main(String[] args) throws Exception {
    HeapFactory.createHeap(new File(args[0])).getBiggestObjectsByRetainedSize(15); // number doesn't matter
  }
}

Minimal pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
   <dependency>
    <groupId>org.netbeans.modules</groupId>
    <artifactId>org-netbeans-lib-profiler</artifactId>
    <version>RELEASE180</version>
   </dependency>
  </dependencies>
</project>

Dump causing issues: triggering-dump.zip

I narrowed it down to the tags from computeGCRootsFor(heap.getHeapTagBound(HprofHeap.ROOT_STICKY_CLASS), rootList); being somehow wrong. Commenting out the sticky class in HprofGCRoots avoids the crash, but obviously isn't correct.

Did this work correctly in an earlier version?

No / Don't know

Operating System

RHEL8.8

JDK

openjdk 1.8.0.372 && oracle 17.0.6

Apache NetBeans packaging

Other

Anything else

From maven jars.

Triggering hprof: triggering-dump.zip

Are you willing to submit a pull request?

No

mbien commented 11 months ago

@thurka you are probably the most qualified to take a look at this since you wrote it. I suppose the heapdump format changed?