如果在分配变量之前使用了变量,Eclipse将丢失警告 [英] Eclipse missing warning if variable used before assigned
问题描述
我们在旧代码中发现了一个错误,如果有警告,可以很容易地找到它,
We found a bug in old code which could be easily found if there would be a warning,
问题是内部类成员已使用但未分配或初始化.示例代码已最小化.问题是 url
始终为null.
The issue was that inner class member was used but not assigned or initialized. Sample code minimized. Problem is that url
is always null.
public class Main {
public class Sender {
private String url;
public Sender() {
}
public void send() {
OtherClass.send(url);
}
}
}
在 intellij 中,它会警告变量永不已分配.在月食中,我没有发现这样的警告.
In intellij it warns about variable never assigned. In eclipse I didn't find such warning.
代码更加复杂,在任何级别添加警告都会减少发现类似错误的时间.
The code is more complex and adding a warning at any level will reduce time to find similar bugs.
如果在分配/初始化之前使用了变量,在eclipse中是否可以通过某种方式发出警告?
Is it possible in eclipse to warn in some way if variable is used before assigned/initialized ?
推荐答案
您可以使用SpotBugs(findbugs的后继产品)eclipse插件.右键单击项目Spotbugs->查找错误,这将找到这些类型的错误.
You can use SpotBugs(successor of findbugs) eclipse plugin. Right click on project Spotbugs->find bugs this will find these types of bugs.
我建议还安装具有良好静态分析功能的sonarlint插件.
I suggest also installing sonarlint plugin which has good static analysis capabilities.
https://marketplace.eclipse.org/content/spotbugs-eclipse-plugin
https://marketplace.eclipse.org/content/sonarlint
这篇关于如果在分配变量之前使用了变量,Eclipse将丢失警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!