在尝试设置断点时,我在Eclipse中得到这个奇怪的错误。
Unable to insert breakpoint Absent Line Number Information
我勾选了编译器选项的复选框,但运气不好。
在尝试设置断点时,我在Eclipse中得到这个奇怪的错误。
Unable to insert breakpoint Absent Line Number Information
我勾选了编译器选项的复选框,但运气不好。
当前回答
有一次我在使用junit和Mockito时遇到了同样的错误,我忘记为静态类添加@PrepareForTest。
添加以下代码修复了我的问题。
@PrepareForTest({XXXXX.class})
不确定是不是同一个案子。
其他回答
这里有详细的解释:
https://github.com/spring-projects/spring-ide/issues/78
只是为了将来参考,这是答案的相关部分(忽略引用Spring Boot应用程序的事实,在许多其他情况下行为是相同的):
Whenever you set a breakpoint in Eclipse/STS, the IDE tries to set the breakpoint in the VM if you launch an app. That is what happens in your case when you run the boot app in debug mode. For each class that gets loaded into the JVM, the IDE checks whether it needs to set a breakpoint or not. If it decides to set the breakpoint, the tries to do so (using the information from the breakpoint definition in the IDE, including its line number, since you usually set line breakpoints on a source file at a given line). This decision (whether to set the breakpoint on a given loaded class or not) checks the types that you set the breakpoint on, enclosing types, and inner classes. This makes sure that breakpoints for inner classes (even anonymous inner classes) are set to the JVM (and are not ignored). Spring Boot generates an inner class for your controller at runtime (this is the CGLIB generated inner class that appears in the error message). When the JVM loads that class, it tries to set the line number breakpoint of the enclosing type (for this inner class). Since the generated inner class doesn't have any line number information (it doesn't need to have line number information), setting the breakpoint fails for this inner class with the mentioned error message. When the IDE loads the enclosing type (your controller class itself), it also tries to set the line breakpoint and succeeds with that. This is visualized with the check marker on the breakpoint marker. Therefore you can safely ignore the error message that shows up. To avoid this error message to show up, you can go to the preferences (Java -> Debug) and disable "Warn when unable to install breakpoint due to missing line number attributes".
如果上述解决方案不起作用,并且你在做了spring bean注入后开始遇到这个问题,问题可能是你没有为注入类使用接口。尝试使用实现接口的类进行注入可以解决这个问题。下面是一个例子: 无法安装用于创建bean的断点问题
检查/做以下事情:
1)在“窗口—>首选项—> Java—>编译器—>类文件生成”下,所有选项必须为True:
(1) Add variable attributes...
(2) Add line number attributes...
(3) Add source file name...
(4) Preserve unused (never read) local variables
2)在项目的.settings文件夹中,找到一个名为org.eclipse.jdt.core.prefs的文件。 验证或设置org.eclipse.jdt.core.compiler.debug.lineNumber=generate
3)如果仍然出现错误窗口,单击复选框不显示错误信息。
4)清洁和建造项目。开始调试。
正常情况下,错误窗口不再显示,调试信息显示正确。
We have very useful information to solve this problem already, but in my specific case, the problem was that as I did an update to my project from the repository, new classes were generated with the compiled source from the newest code. The problem is that I forgot to change the versions of the projects in my POM files and as the breakpoints were set on the new code and the POM files were still pointing to old versions that were available on the JAR files of a previous compilation, the classes from the JAR files were chosen and not the classes from the new code.
在恢复中,为了解决这个问题,我只需要更新主项目的POM文件的版本,清理并重新编译源代码,最后刷新环境。我希望这能对其他人有用。
我从黑莓SDK方面得到了这个问题的答案:出于某种原因,无论我在编译器中修改了多少次选项,实际的底层设置文件都没有改变。
在项目的.settings文件夹中查找一个名为org.eclipse.jdt.core.prefs的文件。
在那里你可以手动修改设置:
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
编辑:除此之外,我还注意到有时我可以忽略Eclipse给出的警告,它仍然会停在需要的地方……越来越奇怪……我将此归入我们作为开发人员所需要处理的事情中。