Skip to content

Commit

Permalink
Extend ReturnsNullCollection to cover Multimap.
Browse files Browse the repository at this point in the history
This matters much less now that ReturnMissingNullable is on, but it's also extremely easy to do.

PiperOrigin-RevId: 464846273
  • Loading branch information
cpovirk authored and Error Prone Team committed Aug 2, 2022
1 parent cb1fac8 commit e2309dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private static boolean methodWithoutNullable(MethodTree tree, VisitorState state
allOf(
anyOf(
methodReturns(isSubtypeOf("java.util.Collection")),
methodReturns(isSubtypeOf("java.util.Map"))),
methodReturns(isSubtypeOf("java.util.Map")),
methodReturns(isSubtypeOf("com.google.common.collect.Multimap"))),
ReturnsNullCollection::methodWithoutNullable);

public ReturnsNullCollection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void positive() {
compilationHelper
.addSourceLines(
"Test.java",
"import com.google.common.collect.Multimap;",
"import java.util.Collection;",
"import java.util.ArrayList;",
"import java.util.List;",
Expand All @@ -50,6 +51,10 @@ public void positive() {
" // BUG: Diagnostic contains: ReturnsNullCollection",
" return null;",
" }",
" Multimap<String, String> methodReturnsNullMultimap() {",
" // BUG: Diagnostic contains: ReturnsNullCollection",
" return null;",
" }",
" List<String> methodReturnsNullListConditionally(boolean foo) {",
" if (foo) {",
" // BUG: Diagnostic contains: ReturnsNullCollection",
Expand Down

0 comments on commit e2309dc

Please sign in to comment.