2

The definition of the DU Anomaly says:

DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text.

But that seems to be false for the following code, although the DU - Anomaly shows up:

private void aFancyMethod(final List<SomeObject> resultList, int maxLevel)
{
    int newMaxLevel;
    if (maxLevel < 1)
    {
        newMaxLevel = 1; // DU - Anomaly here
    } else
    {
        newMaxLevel = maxLevel; // DU - Anomaly here
    } 

    for (SomeObject[] revArray : resultList)
    {
        someOtherMethodCall(revArray, currentLevel, newMaxLevel);
    } 
} 

What is the reason the DU - Anomaly is showing up?

danizmax
  • 2,446
  • 2
  • 32
  • 41
  • This definitely looks like a False Positive. Please check to be using the latest PMD version (at this moment, 5.5.4), and if it still reports that, please submit an issue report on PMD's Github: https://github.com/pmd/pmd/issues – Johnco Mar 17 '17 at 13:36

0 Answers0