Home > Back-end >  JDI:How to iterate over HashMap
JDI:How to iterate over HashMap

Time:12-13

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

CodePudding user response:

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>.

CodePudding user response:

mapConfig.forEach((k, v) -> {

});
  • Related