Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add library model for Guava's Closer.register #632

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void setup() {
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber,com.google.common"));
"-XepOpt:NullAway:AnnotatedPackages=com.uber,com.google.common",
"-XepOpt:NullAway:AcknowledgeLibraryModelsOfAnnotatedCode=true"));
}

@Test
Expand Down Expand Up @@ -89,4 +90,32 @@ public void testIterableParametricNullness() {
"}")
.doTest();
}

@Test
public void testCloserParametricNullness() {
defaultCompilationHelper
.addSourceLines(
"Test.java",
"package com.uber;",
"import com.google.common.io.Closer;",
"import java.io.Closeable;",
"import java.io.FileInputStream;",
"import javax.annotation.Nullable;",
"class Test {",
" public static FileInputStream test1(Closer closer, FileInputStream fis1) {",
" // safe: non-null arg to non-null return",
" return closer.register(fis1);",
" }",
" @Nullable",
" public static FileInputStream test2(Closer closer, @Nullable FileInputStream fis2) {",
" // safe: nullable arg to nullable return",
" return closer.register(fis2);",
" }",
" public static FileInputStream test3(Closer closer, @Nullable FileInputStream fis3) {",
" // BUG: Diagnostic contains: returning @Nullable expression",
" return closer.register(fis3);",
" }",
"}")
.doTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ private static class DefaultLibraryModels implements LibraryModels {
private static final ImmutableSetMultimap<MethodRef, Integer> NULL_IMPLIES_NULL_PARAMETERS =
new ImmutableSetMultimap.Builder<MethodRef, Integer>()
.put(methodRef("java.util.Optional", "orElse(T)"), 0)
.put(methodRef("com.google.common.io.Closer", "<C>register(C)"), 0)
.build();

private static final ImmutableSet<MethodRef> NULLABLE_RETURNS =
Expand Down