0

I get through JDI to get com.sun.jdi.ObjectReference is type java.util.HashMap,then i get filed value "entrySet" ,why it is always null? How can i iterate over HashMap keyValues with java debug api?

public static void displayVariables(LocatableEvent event) throws IncompatibleThreadStateException, AbsentInformationException {
        StackFrame stackFrame = event.thread().frame(0);
        for (LocalVariable visibleVariable : stackFrame.visibleVariables()) {
            Value value = stackFrame.getValue(visibleVariable);
            if(value instanceof ObjectReference){
                ObjectReference objectReference = (ObjectReference) value;//is type java.util.HashMap
                Field entrySet = objectReference.referenceType().fieldByName("entrySet");// is java.util.HashMap.entrySet
                Value entrySetValue = objectReference.getValue(entrySet);// is null
                System.out.println(entrySet);

            }
        }
    }

enter image description here

Lson
  • 147
  • 8

2 Answers2

0
for (T key : hashMap.keySet()) {
    V value = hashMap.get(key);
    // rest of your code here
} // Can you get to where you need to go from here?

Assuming hashMap is of type HashMap<T, V>.

hd1
  • 33,938
  • 5
  • 80
  • 91
0
mapConfig.forEach((k, v) -> {

});
Bhushan
  • 104
  • 1
  • 9