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

Remove URI serialization for classes coming from .class files from fix serialization code #752

Merged
merged 2 commits into from
Mar 31, 2023
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 @@ -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);
}
}
Original file line number Diff line number Diff line change
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