Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the Value column for an object in the NetBeans Debugger Variable window?

The NetBeans 8 Debugger Variables window has a Value column. The meaning of the column is pretty self explanatory for primitive types and Strings and Arrays, but for Objects, the column displays a "#" character followed by a (typically 4 digit) number. The value is apparently related to the identity of the object because multiple variables referencing the same object have the same number displayed, and objects constructed consecutively seem to have sequential numbers. The number is not object.hashCode(). Can anyone tell me more about the number being shown? I am specifically wondering if that number can be accessed as a method or property of the object similar to hashCode(). If not, then is there a way to access that number programmatically?

My explanation of the column's meaning corresponds to the last section of https://ui.netbeans.org/docs/hi/debugger3.4/variables/index.html#specific which is entitled "Object Rows". It states that "Object rows are used to show references to class instances. Each reference can be thought of as having the number of a class instance (from some table of instances in the VM), so this number is shown in the value column (prefixed by "#") for the reference."

I am trying to get a better explanation of what the article simply calls "some table of instances in the VM".

Thanks

like image 593
David Avatar asked Apr 22 '15 07:04

David


1 Answers

I don't think there is a way to access that number, unless you are creating debugger plugin. Netbeans just assigns a new number to every new object it encounters during debugging session. The "is the object new" check is probably based directly on identity (==) and not on Object.hashCode()/System.identityHashCode().

You can take "some table of instances in the VM" quite literally. Even if JVM doesn't have explicit tables you can still get such list from heap dump(HPROF). The OQL (Object Query Language) allows for SQL-like access to such data. For example:

select f.field1 from my.package.MyClass f where f.field2 = 123

By the way I ended up in this question looking for a way to display toString() instead of that #number - to get that I had to right-click variable table header and select new column "String value". The alternative way is to add Variable formatter in "Tools/ Option /Java / Java Debugger / Variable formatters"

like image 105
user158037 Avatar answered Nov 09 '22 18:11

user158037