Skip to content

Commit

Permalink
Use qualifier expression from method reference in JdkObsolete.
Browse files Browse the repository at this point in the history
Previously we were using the owner of the symbol of the method from the method reference, but this causes false positives when a method in a non-obsolete API overrides one in an obsolete API.

RELNOTES: none

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=231460198
  • Loading branch information
eaftan authored and ronshapiro committed Jan 31, 2019
1 parent 98c96ec commit c7a178a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -208,9 +208,8 @@ public Description matchClass(ClassTree tree, VisitorState state) {


@Override @Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) { public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
MethodSymbol symbol = ASTHelpers.getSymbol(tree); Symbol sym = ASTHelpers.getSymbol(tree.getQualifierExpression());
return describeIfObsolete( return describeIfObsolete(tree.getQualifierExpression(), ImmutableList.of(sym.asType()), state);
tree.getQualifierExpression(), ImmutableList.of(symbol.owner.asType()), state);
} }


private Description describeIfObsolete( private Description describeIfObsolete(
Expand Down
Expand Up @@ -262,4 +262,22 @@ public void obsoleteMocking() {
"}") "}")
.doTest(); .doTest();
} }

@Test
public void navigableSetRepro() {
testHelper
.addSourceLines(
"Test.java",
"import java.util.NavigableSet;",
"import java.util.Optional;",
"class Test {",
" Optional<Object> fail1(Optional<NavigableSet<Object>> myOptionalSet) {",
" return myOptionalSet.map(NavigableSet::first);",
" }",
" Optional<Object> fail2(Optional<NavigableSet<Object>> myOptionalSet) {",
" return myOptionalSet.map(NavigableSet::last);",
" }",
"}")
.doTest();
}
} }

0 comments on commit c7a178a

Please sign in to comment.