This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 267560 - INSANE follows Class → ClassLoader links but fails to report them
Summary: INSANE follows Class → ClassLoader links but fails to report them
Status: NEW
Alias: None
Product: platform
Classification: Unclassified
Component: NB JUnit (show other bugs)
Version: 8.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Theofanis Oikonomou
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-12 18:24 UTC by Jesse Glick
Modified: 2016-11-08 22:28 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2016-08-12 18:24:50 UTC
While trying to track down a `ClassLoader` leak, whereby one of the loaded `Class`s is held strongly from a data structure, I found that `LiveReferences.fromRoots` called on the `ClassLoader` returns an empty map even though the loader is strongly held. I tracked this down to a couple of missing calls in `InsaneEngine`: while it does traverse the `classLoader` link for purposes of finding objects to process, it fails to properly notify the visitor of this link, making `LiveEngine` unable to report the cause of a memory leak.

https://github.com/jenkinsci/jenkins-test-harness/pull/32/files#diff-00de86199afe99b23cc690ce65ddca02R209 both notes where the calls must be made, and shows how to work around the issue with a `LiveEngine` override. `Path.getField` could probably be improved in this case, but it works well enough as is.

While I am here, I also had an RFE for `LiveEngine`: allow a custom `Filter` to be set, without logically ANDing it with `skipNonStrongReferencesFilter`, so that a caller may look for soft or even weak root references, in case no strong references still seem to be held.

I also tested a couple of assertions which helped develop the fix and workaround (otherwise `Path.getField` can fail with a cryptic `NullPointerException` long after the damage is done):

* The `Path` constructor should throw an exception if `item == null`.
* `LiveEngine.getIncomingRefs` should throw an exception if `oo == null`.
Comment 1 Jesse Glick 2016-11-08 22:28:38 UTC
Some more buglets:

* `InsaneEngine.recognizeObject` should not do anything special about `sun.reflect.` (this case can happen).
* `ScannerUtils.interestingRoots` omits Java Platform classes which have `static` fields that can hold on to application objects. In particular should add:
** Class.forName("java.io.ObjectStreamClass$Caches")
** Class.forName("java.beans.ThreadGroupContext")

Are you accepting patches in this component? I would like to stop needing to maintain more and more workarounds.