Question

I'm debugging some code that uses Map<Integer,...>, but I'm having great difficulty finding the values associated with various Integers! Here's a minimum working example:

java code (saved to .\src):

import java.util.Map;
import java.util.HashMap;

public class Hello {

    public static void main(String[] args) throws java.io.IOException {
        Map<Integer,String> mymap = new HashMap<Integer,String>(2);
        mymap.put(new Integer(5), "five");
        mymap.put(6, "six");
    }
}

Terminal 1 (powershell):

javac -g $(ls . *.java -r -name)
java -cp src -Xdebug '-Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=hey' Hello

Terminal 2 (powershell):

jdb -attach hey

...

VM Started: No frames on the current call stack

main[1] stop at Hello:10
Deferring breakpoint Hello:10.
It will be set after the class is loaded.
main[1] cont
> Set deferred breakpoint Hello:10

Breakpoint hit: "thread=main", Hello.main(), line=10 bci=40

main[1] dump mymap.get(5)
com.sun.jdi.InvalidTypeException: Can't assign primitive value to object
 mymap.get(5) = null
main[1] dump mymap.get(new Integer(5))
com.sun.tools.example.debug.expr.ParseException: No class named: Integer
 mymap.get(new Integer(5)) = null
main[1]

How should I go about looking up a value from a Map<Integer,?>?

Was it helpful?

Solution

Use the fully qualified class name:

dump mymap.get(new java.lang.Integer(5))

OTHER TIPS

Although the java language allows classes within java.lang to be used as though imported, jdb does not.

dump mymap.get(new java.lang.Integer(5))

should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top