Affects PMD Version:
7.7.0
Rule:
UnnecessaryImport
Description:
PMD reports an unnecessary on-demand import. However, if the import is removed the code does not compile
Code Sample demonstrating the issue:
https://github.com/lolo101/pmd-issue
package org.example; import java.util.Map; import java.util.Map.*; // this import is reported as unnecessary. However, class Entry is a nested class of Map and requires that import import static java.util.stream.Collectors.toMap; public class Main { public static void main(String[] args) { Map<String, String> map = Map.of("key1", "value1"); var weirdCopy = map.entrySet().stream().collect(toMap(Entry::getKey, Entry::getValue)); System.out.println(weirdCopy); } }
Expected outcome:
PMD reports a violation at line 4, but that's wrong. That's a false positive.
Running PMD through: Maven with plugin maven-pmd-plugin 3.26.0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4