diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java index e2147cacd45..835b9d1e83e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java @@ -45,10 +45,10 @@ V after(Map map, T key) { } } - /** - * Prefer {@link Map#getOrDefault(Object, Object)} over more contrived alternatives. Note that - * this method may return null instead of throwing a NPE. - */ + /** Prefer {@link Map#getOrDefault(Object, Object)} over more contrived alternatives. */ + // Note that + // XXX: `requireNonNullElse` throws an NPE if the second argument is `null`, while the alternative + // does not. static final class MapGetOrDefault { @BeforeTemplate V before(Map map, T key, V defaultValue) { @@ -56,7 +56,6 @@ V before(Map map, T key, V defaultValue) { } @AfterTemplate - @Nullable V after(Map map, T key, V defaultValue) { return map.getOrDefault(key, defaultValue); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java index a539799cdd0..707243ba4da 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java @@ -13,7 +13,7 @@ final class MapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(HashMap.class, requireNonNullElse("foo", "bar")); + return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null)); } Map testCreateEnumMap() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java index 22d3fd6065c..9214fa6f79f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java @@ -14,7 +14,7 @@ final class MapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(HashMap.class, requireNonNullElse("foo", "bar")); + return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null)); } Map testCreateEnumMap() {