Given a StackTraceElement.getLineNumber(), is there a way to read the content of this line from a compiled class file? And even if it is possible to match the line, would the content of the class file will be “obfuscated” by the compiler?
For example if I had:
public void myMethod () {
MyObj m = new MyObj (); // can I reconstruct this line as String?
}
The source code is not contained by the compiled class file, which contains bytecode; so no, working only from the class file you can’t reconstruct that line of code. It’s possible to de-compile Java bytecode, of course, and a sufficiently well-built decompiler might reconstruct that line of code to a greater or lesser extent, but you’d have to have a decent decompiler. The end results may or may not look much like the original source code, depending on optimisations and such.