Skip to content

Commit

Permalink
Update path serialization for class files (#752)
Browse files Browse the repository at this point in the history
This PR partially resolves #716 by removing URI serialization for classes coming from `.class` files in all serializations.

In Annotator all serialized paths in downstream dependencies analysis phase, are neglected and retrieved from internal data structure of Annotator. Please see [Github](https://github.com/ucr-riple/NullAwayAnnotator/blob/4587c9821f4ccd152c1e6853a0cd10df5bcf277d/annotator-core/src/main/java/edu/ucr/cs/riple/core/cache/downstream/DownstreamImpactEvaluator.java#L85)

I tested Annotator with a local snapshot of NullAway with latest changes in this PR and I did not see any problem.

#716 is partially resolved since it requires updating path constructions in tests as well, which will be addressed in a separate PR.
  • Loading branch information
nimakarimipour committed Mar 31, 2023
1 parent 7714c45 commit abac2ae
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 66 deletions.
Expand Up @@ -53,15 +53,7 @@ public AbstractSymbolLocation(ElementKind type, Symbol target) {
+ ".");
this.type = type;
this.enclosingClass = castToNonNull(ASTHelpers.enclosingClass(target));
// We currently serialize the URI for the classfile if the URI for the sourcefile is not
// available, but only if said URI corresponds to a "file:" or "jimfs:" scheme (i.e. not
// "jar:"). It's likely that this is no longer needed and should be removed as a follow up:
// https://github.com/uber/NullAway/issues/716 Leaving this workaround up temporarily for the
// sake of experiments with version `1.3.6-alpha-N` of the auto-annotator.
URI pathInURI =
enclosingClass.sourcefile != null
? enclosingClass.sourcefile.toUri()
: (enclosingClass.classfile != null ? enclosingClass.classfile.toUri() : null);
URI pathInURI = enclosingClass.sourcefile != null ? enclosingClass.sourcefile.toUri() : null;
this.path = Serializer.pathToSourceFileFromURI(pathInURI);
}
}
Expand Up @@ -1638,63 +1638,6 @@ public void suggestNullableArgumentOnBytecodeNoFileInfo() {
}
}

@Test
public void suggestNullableArgumentOnBytecodeClassFileInfoOnly() {
// Simulate a build system which elides sourcefile/classfile info
try (MockedStatic<ASTHelpers> astHelpersMockedStatic =
Mockito.mockStatic(ASTHelpers.class, Mockito.CALLS_REAL_METHODS)) {
astHelpersMockedStatic
.when(() -> ASTHelpers.enclosingClass(any(Symbol.class)))
.thenAnswer(
(Answer<Symbol.ClassSymbol>)
invocation -> {
Symbol.ClassSymbol answer = (Symbol.ClassSymbol) invocation.callRealMethod();
if (answer.sourcefile != null
&& answer
.sourcefile
.toUri()
.toASCIIString()
.contains("com/uber/nullaway/testdata/unannotated")) {
answer.sourcefile = null;
}
return answer;
});
SerializationTestHelper<FixDisplay> tester = new SerializationTestHelper<>(root);
tester
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
// Explicitly avoid excluding com.uber.nullaway.testdata.unannotated,
// so we can suggest fixes there
"-XepOpt:NullAway:SerializeFixMetadata=true",
"-XepOpt:NullAway:FixSerializationConfigPath=" + configPath))
.addSourceLines(
"com/uber/UsesUnannotated.java",
"package com.uber;",
"import com.uber.nullaway.testdata.unannotated.MinimalUnannotatedClass;",
"public class UsesUnannotated {",
" Object test(boolean flag) {",
" // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required",
" return MinimalUnannotatedClass.foo(null);",
" }",
"}")
.setExpectedOutputs(
new FixDisplay(
"nullable",
"foo(java.lang.Object)",
"x",
"PARAMETER",
"com.uber.nullaway.testdata.unannotated.MinimalUnannotatedClass",
// From Symbol.classfile!
"com/uber/nullaway/testdata/unannotated/MinimalUnannotatedClass.java"))
.setFactory(fixDisplayFactory)
.setOutputFileNameAndHeader(SUGGEST_FIX_FILE_NAME, SUGGEST_FIX_FILE_HEADER)
.doTest();
}
}

@Test
public void fieldRegionComputationWithMemberSelectTest() {
SerializationTestHelper<ErrorDisplay> tester = new SerializationTestHelper<>(root);
Expand Down

0 comments on commit abac2ae

Please sign in to comment.