Inevitable DD Anomaly in PMD

I came across a special case where I cannot solve the DD anomaly in PMD. Assume the code is:

BigDecimal amount = BigDecimal.ZERO;
for(int i=0;i<5;i++)
{
      amount = amount.add(i);
}
return amount;

When you run this code through PMD, it will show the DD anomaly when declaring the amount. However, if I remove the initialization, I will get an exception. How can this situation go through PMD. Is anyone

+5
source share
1 answer

On the "Inconsistent Rules" page , the DataflowAnomalyAnalysis section:

DD - Anomaly: recently redefined variable. It is ominous, but not necessary to be a mistake.

. . ( , , , , .)

, , . , " " - , . , , , , .

+10

All Articles