java的循环标记,每个循环的Java被PMD标记为UR异常

I would like to confirm if this is a bug on PMD? How do I file a ticket if it is.

public static void main(final String[] args) {

for (final String string : args) {

string.getBytes(); //UR Anomaly

}

for (int i = 0; i < args.length; i++) {

args[i].getBytes();

}

}

Lines 1-3 are being flagged as UR anomaly, while rewriting it to iterate with a local variable is fine.

Would like to eliminate as much PMD violations, but it is inconvenient to have to resort to old loop construct as a workaround.

While controversial, I do not wish to disable this rule since I find DD, and DU anomaly flagging as useful.

解决方案

It appears that you have hit a bug in PMD. The DataflowAnomalyAnalysis rule does not seem to catch all possible kinds of variable definitions (another example found here).

UR stands for "undefined reference", which is obviously incorrect.

So, what can you do?

Since the problem appears to affect mostly the UR part of the rule, you can disable it and continue using the DU and DD parts. You need a fairly recent version of PMD to do this. In your ruleset file, suppress UR findings like this:

In my humble opinion, the whole UR checking is a bit over the top, because the compiler will not accept undefined references. And these days, running the compiler is no longer such a big deal.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值