Getting location of .class file being run by the debugger (the VM)

Stepping through debugging and it appears the debugger is going to the wrong line of the source . That usually means the source in the editor is not the source of the compiled code being run in the VM. I've tried all the ways I know to recompile the source and make sure it's outputting to the correct place so the source in my editor and the .class file are in sync. I've checked and rechecked all known output paths etc.etc. I can't tell if I am just misunderstanding something (likely) or (unlikely) there's  a bug in the debugger that I've uncovered.

What would set me on the path to understanding this and all like problems in the future is a way to see from whence the compiled code is being loaded, that is, an answer to this question- what is the absolute path of the directory of the .class file the debugger is now in?

Anyone know of such a trick?

3 comments
Comment actions Permalink

From the class you can get a ProtectionDomain this has a CodeSource object that has a location of the directory or archive the class was loaded from.

Rod

0
Comment actions Permalink

Excellent answer! Unfortunately, the code I have access to is not the .class file :( which is apparently being run. But that is the best way.. I tried do the PotectionDomain thing in the debugger evaluate expression but because it's in a jar (somewehre.. somewhere..) , it gave me null on account of the jar not being signed. That is apparently some safety feature built into the SecurityManager or suchlike :(:(:(

0
Comment actions Permalink

There may be some instrumentation happening in the app that's garbling line numbers.
Try "main menu/view/show byte code" standing on that file. It should contain LINE information.

0

Please sign in to leave a comment.