Trying to watch the values in a collection of Objects
I have a class, which contains a Collection of Objects and I wish to inspect the values of one of the properties for every object in that collection.
For example, I have a class called A, which contains a collection of objects of type B, which in turn have a variable of type C (which happens to reference an enum if that makes any difference.) I want to be able to examine, during debugging, the values of all the C variables of the B objects.
I had thought that if I placed a watch on A, I would simply be able to expand the reference to A and drill down to the Bs & Cs - which I can do if I place a breakpoint in the code, but a breakpoint isn't helpful here as I want the code to continue running as I watch things. However, I can't find any way to expand the reference to A. If I click "Inspect" it simply opens up a dialog with the reference listed, but no way to expand it.
I've also tried placing watches on B and C, but I get the same result - no option to expand them and see what data they contain.
I'm obviously missing something as I'm sure this must be a common requirement and something that all debuggers can do, but I simply can't figure it out.
I hope my question makes sense!
Please sign in to leave a comment.
Hi Paul,
> which I can do if I place a breakpoint in the code, but a breakpoint isn't helpful here as I want the code to continue running as I watch things
Java VM does not allow debugger to query data or explore variable's state unless there are paused threads. I mean you can analyse memory objects only within a context of a paused thread. In order to perform evaluations, the thread not only has to be paused, but also has to be paused as a result of a breakpoint hit. Some debugger data renderers are using methods invocation (like 'toString()' renderer), and such renderers will be unavailable if you simply pause program execution with the corresponding button: you will still be able to explore memory objects, but without 'fancy' representation.
To get the most from debugger views, the thread has to be paused at a breakpoint. These are restrictions imposed by VM, so we can only live with them and adapt debugging techniques accordingly.