[java] UnusedLocalVariable: false positive - parenthesis
A source code analyzer
Brought to you by:
adangel,
juansotuyo
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("first");
list.add("second");
int notEmpty = 0;
for (String string : list) {
if (!string.isEmpty()) {
notEmpty++;
}
}
System.out.println(list.size() + " (" + (notEmpty) + " not empty)");
}
}
notEmpty is reported as UnusedLocalVariable. If I remove the parentheses arround notEmpty everything is OK.
Thanks for reporting this bug. It will be fixed with PMD 5.3.8, PMD 5.4.2, PMD 5.5.0 and later.
Commit: https://github.com/pmd/pmd/commit/0d20fe7e1c66568b4aa1a5c40b48621ac5a911bd