Skip to content
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 @@ -37,7 +37,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import com.google.errorprone.VisitorState;
import com.google.errorprone.util.ASTHelpers;
Expand Down Expand Up @@ -1669,8 +1668,8 @@ private static class ExternalStubxLibraryModels implements LibraryModels {

private final Map<String, Map<String, Map<Integer, Set<String>>>> argAnnotCache;
private final Set<String> nullMarkedClassesCache;
private final Map<String, Integer> upperBoundsCache;
private final Multimap<String, Integer> methodTypeParamNullableUpperBoundCache;
private final SetMultimap<String, Integer> upperBoundsCache;
private final SetMultimap<String, Integer> methodTypeParamNullableUpperBoundCache;
private final Map<String, SetMultimap<Integer, NestedAnnotationInfo>> nestedAnnotationInfo;

ExternalStubxLibraryModels(boolean isJarInferEnabled, boolean isJSpecifyJDKEnabled) {
Expand Down Expand Up @@ -1746,7 +1745,7 @@ public ImmutableSet<String> nullMarkedClasses() {
public ImmutableSetMultimap<String, Integer> typeVariablesWithNullableUpperBounds() {
ImmutableSetMultimap.Builder<String, Integer> mapBuilder =
new ImmutableSetMultimap.Builder<>();
for (Map.Entry<String, Integer> entry : upperBoundsCache.entrySet()) {
for (Map.Entry<String, Integer> entry : upperBoundsCache.entries()) {
Comment thread
msridhar marked this conversation as resolved.
mapBuilder.put(entry.getKey(), entry.getValue());
}
return mapBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import com.uber.nullaway.jarinfer.JarInferStubxProvider;
import com.uber.nullaway.libmodel.NestedAnnotationInfo;
Expand Down Expand Up @@ -71,7 +70,7 @@ private void LOG(boolean cond, String tag, String msg) {

private final Map<String, Map<String, Map<Integer, Set<String>>>> argAnnotCache;

private final Map<String, Integer> upperBoundCache;
private final SetMultimap<String, Integer> upperBoundCache;

private final Set<String> nullMarkedClassesCache;

Expand All @@ -89,7 +88,7 @@ private void LOG(boolean cond, String tag, String msg) {
*/
StubxCacheUtil(String logCaller, boolean loadJarInferModels) {
argAnnotCache = new LinkedHashMap<>();
upperBoundCache = new HashMap<>();
upperBoundCache = HashMultimap.create();
nullMarkedClassesCache = new HashSet<>();
methodTypeParamNullableUpperBoundCache = HashMultimap.create();
nestedAnnotationInfoCache = new HashMap<>();
Expand All @@ -99,15 +98,15 @@ private void LOG(boolean cond, String tag, String msg) {
}
}

public Map<String, Integer> getUpperBoundCache() {
public SetMultimap<String, Integer> getUpperBoundCache() {
return upperBoundCache;
}

public Set<String> getNullMarkedClassesCache() {
return nullMarkedClassesCache;
}

public Multimap<String, Integer> getMethodTypeParamNullableUpperBoundCache() {
public SetMultimap<String, Integer> getMethodTypeParamNullableUpperBoundCache() {
return methodTypeParamNullableUpperBoundCache;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,26 @@ void testNonNullContents(List<String> list) {
""")
.doTest();
}

@Test
public void biConsumerNullableUpperBound() {
makeHelper()
.addSourceLines(
"Test.java",
"""
import org.jspecify.annotations.*;
import java.util.function.*;
@NullMarked
class Test {
// test that we can make both type arguments @Nullable
@Nullable BiConsumer<@Nullable Object, @Nullable Object> b = null;
}
""")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
JSpecifyJavacConfig.withJSpecifyModeArgs(List.of("-XepOpt:NullAway:OnlyNullMarked=true")));
}
}
Loading