Skip to content

Commit

Permalink
Revert "Fix serialization field region computation bug fix (uber#689)"
Browse files Browse the repository at this point in the history
This reverts commit b8dde69.
  • Loading branch information
msridhar committed Jul 18, 2023
1 parent ba96f9e commit 8e92cc7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void findValues() {
// Node is not enclosed by any method, can be a field declaration or enclosed by it.
Symbol sym = ASTHelpers.getSymbol(path.getLeaf());
Symbol.VarSymbol fieldSymbol = null;
if (sym != null && sym.getKind().isField() && sym.isEnclosedBy(classSymbol)) {
if (sym != null && sym.getKind().isField()) {
// Directly on a field declaration.
fieldSymbol = (Symbol.VarSymbol) sym;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1662,151 +1662,4 @@ public void verifySerializationVersionIsSerialized() {
"Could not read serialization version at path: " + serializationVersionPath, e);
}
}

@Test
public void fieldRegionComputationWithMemberSelectTest() {
SerializationTestHelper<ErrorDisplay> tester = new SerializationTestHelper<>(root);
tester
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:SerializeFixMetadata=true",
"-XepOpt:NullAway:FixSerializationConfigPath=" + configPath))
.addSourceLines(
"com/uber/A.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"public class A {",
" B b1 = new B();",
" @Nullable B b2 = null;",
" // BUG: Diagnostic contains: assigning @Nullable expression to @NonNull field",
" Object baz1 = b1.foo;",
" // BUG: Diagnostic contains: dereferenced expression b2 is @Nullable",
" Object baz2 = b2.foo;",
" // BUG: Diagnostic contains: assigning @Nullable expression to @NonNull field",
" Object baz3 = b1.nonnullC.val;",
" // BUG: Diagnostic contains: dereferenced expression b1.nullableC is @Nullable",
" @Nullable Object baz4 = b1.nullableC.val;",
"}",
"class B {",
" @Nullable Object foo;",
" C nonnullC = new C();",
" @Nullable C nullableC = new C();",
"}",
"class C {",
" @Nullable Object val;",
"}")
.setExpectedOutputs(
new ErrorDisplay(
"ASSIGN_FIELD_NULLABLE",
"assigning @Nullable expression to @NonNull field",
"com.uber.A",
"baz1",
"FIELD",
"com.uber.A",
"null",
"baz1",
"null",
"com/uber/A.java"),
new ErrorDisplay(
"ASSIGN_FIELD_NULLABLE",
"assigning @Nullable expression to @NonNull field",
"com.uber.A",
"baz2",
"FIELD",
"com.uber.A",
"null",
"baz2",
"null",
"com/uber/A.java"),
new ErrorDisplay(
"ASSIGN_FIELD_NULLABLE",
"assigning @Nullable expression to @NonNull field",
"com.uber.A",
"baz3",
"FIELD",
"com.uber.A",
"null",
"baz3",
"null",
"com/uber/A.java"),
new ErrorDisplay(
"DEREFERENCE_NULLABLE",
"dereferenced expression b2 is @Nullable",
"com.uber.A",
"baz2"),
new ErrorDisplay(
"DEREFERENCE_NULLABLE",
"dereferenced expression b1.nullableC is @Nullable",
"com.uber.A",
"baz4"))
.setFactory(errorDisplayFactory)
.setOutputFileNameAndHeader(ERROR_FILE_NAME, ERROR_FILE_HEADER)
.doTest();
}

@Test
public void fieldRegionComputationWithMemberSelectForInnerClassTest() {
SerializationTestHelper<ErrorDisplay> tester = new SerializationTestHelper<>(root);
tester
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:SerializeFixMetadata=true",
"-XepOpt:NullAway:FixSerializationConfigPath=" + configPath))
.addSourceLines(
"com/uber/A.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"public class A {",
" Other other1 = new Other();",
" @Nullable Other other2 = null;",
" public void bar(){",
" class Foo {",
" // BUG: Diagnostic contains: assigning @Nullable expression to @NonNull field",
" Object baz1 = other1.foo;",
" // BUG: Diagnostic contains: dereferenced expression other2 is @Nullable",
" Object baz2 = other2.foo;",
" }",
" }",
"}",
"class Other {",
" @Nullable Object foo;",
"}")
.setExpectedOutputs(
new ErrorDisplay(
"ASSIGN_FIELD_NULLABLE",
"assigning @Nullable expression to @NonNull field",
"com.uber.A$1Foo",
"baz1",
"FIELD",
"com.uber.A$1Foo",
"null",
"baz1",
"null",
"com/uber/A.java"),
new ErrorDisplay(
"ASSIGN_FIELD_NULLABLE",
"assigning @Nullable expression to @NonNull field",
"com.uber.A$1Foo",
"baz2",
"FIELD",
"com.uber.A$1Foo",
"null",
"baz2",
"null",
"com/uber/A.java"),
new ErrorDisplay(
"DEREFERENCE_NULLABLE",
"dereferenced expression other2 is @Nullable",
"com.uber.A$1Foo",
"baz2"))
.setFactory(errorDisplayFactory)
.setOutputFileNameAndHeader(ERROR_FILE_NAME, ERROR_FILE_HEADER)
.doTest();
}
}

0 comments on commit 8e92cc7

Please sign in to comment.