DuplicateMapKeys
Map#ofEntries will throw an IllegalArgumentException if there are any duplicate keys

Severity
ERROR
Has Fix?
NO_FIX

The problem

JDK 9 has Map#ofEntries factory which throws runtime error when provided multiple entries with the same key.

For eg, the following code is erroneously adding two entries with Foo as key.

Map<String, String> map = Map.ofEntries(
    Map.entry("Foo", "Bar"),
    Map.entry("Ping", "Pong"),
    Map.entry("Kit", "Kat"),
    Map.entry("Foo", "Bar"));

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("DuplicateMapKeys") to the enclosing element.