【发布时间】:2013-05-19 02:00:29
【问题描述】:
我正在使用带有 PMD Plug-in (4.0.0.v20130510-1000) 的 Eclipse 并且遇到了很多这样的违规行为:
Found 'DD'-anomaly for variable 'freq' (lines '187'-'189').Found 'DU'-anomaly for variable 'freq' (lines '189'-'333').
在this SO 答案中,它说这些异常与分配从未读取过的值有关。但我在这种情况下得到了违规行为:
// here I get a DD anomaly
double freq = 0;
try {
// here I get a DU anomaly
freq = Double.parseDouble(getFrequencyTextField().getText());
} catch (final NumberFormatException e) {
Log.e(e.getMessage());
}
if (freq < 10E6) doSomething();
如果我删除初始化并在catch 块中添加freq = 0; 行,DD 异常就会消失,但我在两个分配上都得到一个 DU 异常。
现在我的问题是:我应该如何处理? PMD 的首选解决方案是什么?这条规则到底是为了防止什么(即为什么这是不好的做法)?
【问题讨论】:
标签: java pmd dataflow anomaly-detection