问题
Does using lombok in java class will result in wrong line numbers in stacktrace ?
Assumption : No delombok has been used on the code.
Lombok does not interrupt with line number generation but it would generate code wherever the annotations are placed. These line nos. would be part of byte code and hence when in stacktrace is printed, it would contain wrong line nos. Is my above interpretation correct ?
回答1:
The line numbers are stored in the .class file by the Java compiler based on the actual lines of the .java source code file.
Lombok hooks into the compilation process itself, modifying the bytecode that is written into the .class file on the fly. It never actually adds text to the .java source file and it also does not alter the line number information the compiler stores in the .class file.
Therefore, the line numbers in stack traces always match the actual Java source code.
Note: The question ruled out the "delombok" case. For interested readers: you can use the "delombok" plugin to generate plain .java code that incorporates everything that Lombok would otherwise put in during compilation. The tool is intended for situations like removing Lombok from a code base, or feeding source code to an analyzer tool that is confused by Lombok stuff. In that case, you end up with different, larger .java source files, which of course have different line numbers.
来源:https://stackoverflow.com/questions/37908097/line-numbers-generation-with-lombok