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 @@ -83,10 +83,13 @@ static void testPositive() {
public void libraryModelWithoutJarInferEnabledTest() {
compilationHelper
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber"))
// Run this test in JSpecify mode to ensure that loading of JDK models does not also
// load external astubx files from JarInfer
JSpecifyJavacConfig.withJSpecifyModeArgs(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run this one in JSpecify mode to ensure that loading of JDK models does not also load external astubx files from JarInfer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth putting this comment into the code itself?

Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber")))
.addSourceLines(
"Test.java",
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ public final class JSpecifyJavacConfig {
public static final String ADD_TYPE_ANNOTATIONS_FLAG = "-XDaddTypeAnnotationsToSymbol=true";
public static final String HANDLE_WILDCARD_GENERICS_FLAG =
"-XepOpt:NullAway:HandleWildcardGenerics=true";
public static final String USE_JSPECIFY_JDK_MODELS = "-XepOpt:NullAway:JSpecifyJDKModels=true";

private static final List<String> JSPECIFY_MODE_ARGS =
List.of(JSPECIFY_MODE_FLAG, ADD_TYPE_ANNOTATIONS_FLAG, HANDLE_WILDCARD_GENERICS_FLAG);
List.of(
JSPECIFY_MODE_FLAG,
ADD_TYPE_ANNOTATIONS_FLAG,
HANDLE_WILDCARD_GENERICS_FLAG,
USE_JSPECIFY_JDK_MODELS);

private JSpecifyJavacConfig() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ private static class ExternalStubxLibraryModels implements LibraryModels {

ExternalStubxLibraryModels(boolean isJarInferEnabled, boolean isJSpecifyJDKEnabled) {
String libraryModelLogName = "LM";
StubxCacheUtil cacheUtil = new StubxCacheUtil(libraryModelLogName);
StubxCacheUtil cacheUtil = new StubxCacheUtil(libraryModelLogName, isJarInferEnabled);
if (isJarInferEnabled) {
// hardcoded loading of stubx files from android-jarinfer-models-sdkXX artifacts
try (InputStream androidStubxIS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,23 @@ private void LOG(boolean cond, String tag, String msg) {
private final Map<String, SetMultimap<Integer, NestedAnnotationInfo>> nestedAnnotationInfoCache;

/**
* Initializes a new {@code StubxCacheUtil} instance.
*
* <p>This sets up the caches for argument annotations and upper bounds, sets the log caller, and
* loads the stubx files.
* Initializes a new {@code StubxCacheUtil} instance, optionally loading JarInfer stubx files
* discovered on the classpath.
*
* @param logCaller Identifier for logging purposes.
* @param loadJarInferModels whether to load stubx files provided by {@link JarInferStubxProvider}
* implementations
*/
public StubxCacheUtil(String logCaller) {
StubxCacheUtil(String logCaller, boolean loadJarInferModels) {
argAnnotCache = new LinkedHashMap<>();
upperBoundCache = new HashMap<>();
nullMarkedClassesCache = new HashSet<>();
methodTypeParamNullableUpperBoundCache = HashMultimap.create();
nestedAnnotationInfoCache = new HashMap<>();
this.logCaller = logCaller;
loadStubxFiles();
if (loadJarInferModels) {
loadStubxFiles();
}
}

public Map<String, Integer> getUpperBoundCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ void use(Attributes attrs) {
public void listContainingNullsWithModel() {
makeTestHelperWithArgs(
JSpecifyJavacConfig.withJSpecifyModeArgs(
List.of(
"-XepOpt:NullAway:AnnotatedPackages=foo",
"-XepOpt:NullAway:JSpecifyJDKModels=true")))
List.of("-XepOpt:NullAway:AnnotatedPackages=foo")))
.addSourceLines(
"Test.java",
"""
Expand Down Expand Up @@ -66,8 +64,13 @@ void testNonNullContents(List<String> list) {
@Test
public void listContainingNullsWithoutModel() {
makeTestHelperWithArgs(
JSpecifyJavacConfig.withJSpecifyModeArgs(
List.of("-XepOpt:NullAway:AnnotatedPackages=foo")))
// We specifically exclude the JSpecifyJDKModels flag here (so we can't use
// `withJSpecifyModeArgs`)
List.of(
"-XepOpt:NullAway:AnnotatedPackages=foo",
JSpecifyJavacConfig.JSPECIFY_MODE_FLAG,
JSpecifyJavacConfig.ADD_TYPE_ANNOTATIONS_FLAG,
JSpecifyJavacConfig.HANDLE_WILDCARD_GENERICS_FLAG))
.addSourceLines(
"Test.java",
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,9 @@ public void testForNullTypeRhsTypeForArrayType() {
class Test {
static void testNegative() {
List<String> a = new ArrayList<String>();
Object[] o = a != null ? a.toArray() : null;
// TODO fix imprecise model of toArray()
// https://github.com/uber/NullAway/issues/1616
@Nullable Object[] o = a != null ? a.toArray() : null;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
""")
Expand Down Expand Up @@ -2582,6 +2584,8 @@ public class Test {
static class K<T extends @Nullable Object> {}
void foo(K<@Nullable Object> k) {
K<? extends @Nullable Object> k2 = k;
// TODO should get no error here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed by #1647

// BUG: Diagnostic contains: returning @Nullable
Supplier<? extends @Nullable Object> s = () -> null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static Optional<Double> sumDoubles(@Nullable Double... doubles) {

static Optional<Double> sumDoublesMissingfilter(@Nullable Double... doubles) {
return Arrays.stream(doubles)
// BUG: Diagnostic contains: incompatible types
// BUG: Diagnostic contains: parameter a of referenced method is @NonNull
.reduce(Double::sum);
}

Expand Down
Loading