Issue
How to disable the special treatment of logical structures in eclipse's Variables View?
Summary
Classes implementing java.util.Collection
or java.util.Map
are rendered by calling the respective
[entrySet().]toArray()
methods and shown in a tree-ish structure.
The corresponding preference page is Java -> Debug -> Logical Structures
, where the definitions for java.util.Collection
and java.util.Map
are predefined and cannot be altered or disabled.
My particular situation
Whenever the code enters my collection class in debug mode it immediately tries to call toArray()
in the background (1) (probably due to the this
node being present in the Variables View). However, at some points, the class is just not ready for it and crashes.
I'm fully aware that methods like toArray()
should be free of side-effects and in the project I'm currently working on I can safely leave them empty for the stage of development (or modify them so they don't hurt me), but I'd like to deal with this the 'eclipse way'.
Thus it would be much worse (basically unavoidable), if for example the code of toArray()
itself needed to be debugged.
Notes
(1) confirmation code
@Override
public Object[] toArray() {
new Exception("toArray was called").printStackTrace(System.out);
return super.toArray();
}
However, the resulting stack-trace is completely broken; I don't call that toArray()
at line 45 in Testing
(I don't even have such an object reference), but it was the line I debugged when eclipse's toArray()
kicked in.
java.lang.Exception: toArray was called
at prv.izruo.<project>.util.SAXParser$CursorObject$1.toArray(SAXParser.java:511)
at prv.izruo.<project>.test.Testing.read(Testing.java:45)
at prv.izruo.<project>.test.Testing.main(Testing.java:36)
Solution
The 'eclipse way' in this case is not disabling an existing feature, but overriding it with another, more precise feature.
In particular this means adding another definition in the already mentioned preference page, that refers to a type more precise than java.util.Collection
, let's say SAXParser.CursorObject
(just ignoring the anonymous inner type for the sake of this example - actually its superclass must be used).
This will cut off unwanted calls to toArray()
for all instances of SAXParser.CursorObject
, but preserve the same behavior for all other instances of java.util.Collection
.
So, in a nutshell:
- Go to
Java -> Debug -> Logical Structures
. - Hit
Add...
. - Select the class to 'disable' the behavior for.
- Add a description (because eclipse will force you to do so).
- Insert code that doesn't hurt you.
Answered By - Izruo