Skip to content

Commit

Permalink
Warn about returning a null Table, too.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 621206548
  • Loading branch information
cpovirk authored and Error Prone Team committed Apr 2, 2024
1 parent e4c9409 commit 0c12a77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -54,7 +54,8 @@ private static boolean methodWithoutNullable(MethodTree tree, VisitorState state
anyOf(
methodReturns(isSubtypeOf("java.util.Collection")),
methodReturns(isSubtypeOf("java.util.Map")),
methodReturns(isSubtypeOf("com.google.common.collect.Multimap"))),
methodReturns(isSubtypeOf("com.google.common.collect.Multimap")),
methodReturns(isSubtypeOf("com.google.common.collect.Table"))),
ReturnsNullCollection::methodWithoutNullable);

public ReturnsNullCollection() {
Expand Down
Expand Up @@ -34,6 +34,7 @@ public void positive() {
.addSourceLines(
"Test.java",
"import com.google.common.collect.Multimap;",
"import com.google.common.collect.Table;",
"import java.util.Collection;",
"import java.util.ArrayList;",
"import java.util.List;",
Expand All @@ -55,6 +56,10 @@ public void positive() {
" // BUG: Diagnostic contains: ReturnsNullCollection",
" return null;",
" }",
" Table<String, String, String> methodReturnsNullTable() {",
" // BUG: Diagnostic contains: ReturnsNullCollection",
" return null;",
" }",
" List<String> methodReturnsNullListConditionally(boolean foo) {",
" if (foo) {",
" // BUG: Diagnostic contains: ReturnsNullCollection",
Expand Down

0 comments on commit 0c12a77

Please sign in to comment.