Thursday, January 3, 2019

Java jdb Error: "ERROR: transport error 202: getaddrinfo: unknown host"

I was trying to debug a java program on the command line using the Java jdb debugger when I was faced with a "transport error 202: getaddrinfo: unknown host" error:
$ jdb MyProg
Initializing jdb ...
> run
run MyProg
VM start exception: VM initialization failed for: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,address=mycomputername.local:58341,suspend=y MyProg

ERROR: transport error 202: getaddrinfo: unknown host
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [:732]

Fatal error:
Target VM failed to initialize.
The jdb documentation has this to say:
C:\> jdb MyClass
When started this way, jdb invokes a second Java VM with any specified parameters, loads the specified class, and stops the VM before executing that class's first instruction.
We can see the exact command jdb used do run this second Java VM in the error output above:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=mycomputername.local:58341,suspend=y MyProg
The problem seemed to occur when jdb was trying to resolve the host name "mycomputername.local".
getaddrinfo: unknown host
Adding the host mycomputername.local to my Mac /etc/hosts did the trick.

/etc/hosts:

127.0.0.1    localhost
127.0.0.1    mycomputername.local
After that change jdb was able to run the class without any issues.
$ jdb MyProg
Initializing jdb ...
> run
run MyProg
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: 

Hello World

The application exited

References

jdb - The Java Debugger
https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html
JDWP - Java Debug Wire Protocol
https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/introclientissues005.html
getaddrinfo
http://man7.org/linux/man-pages/man3/getaddrinfo.3.html