龙目岛的行号生成 [英] Line Numbers Generation with Lombok

查看:116
本文介绍了龙目岛的行号生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java类中使用lombok是否会导致stacktrace中的行号错误? 假设:代码上未使用delombok.

Does using lombok in java class will result in wrong line numbers in stacktrace ? Assumption : No delombok has been used on the code.

Lombok不会用line number generation中断,但是无论放置注释的位置如何,Lombok都会生成代码.这些行号.将是字节码的一部分,因此当打印stacktrace中时,它将包含错误的行号.我的上述解释正确吗?

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 ?

推荐答案

Java编译器根据.java源代码文件的实际行将行号存储在.class文件中.

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可以直接进入编译过程,从而修改动态写入.class文件的字节码.它实际上不会向.java源文件中添加文本,也不会更改编译器存储在.class文件中的行号信息.

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.

因此,堆栈跟踪中的行号始终与实际的Java源代码匹配.

Therefore, the line numbers in stack traces always match the actual Java source code.

注意:该问题排除了"delombok"的情况.对于感兴趣的读者:您可以使用"delombok"插件生成简单的.java代码,其中包含Lombok在编译过程中可能放入的所有内容.该工具适用于从代码库中删除Lombok或将源代码提供给被Lombok混淆的分析器工具的情况.在这种情况下,您最终会得到不同的更大的.java源文件,这些文件当然具有不同的行号.

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.

这篇关于龙目岛的行号生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆