Skip to content

Commit

Permalink
Don't crash when a lambda parameter's type is an inner class in the d…
Browse files Browse the repository at this point in the history
…efault package.

PiperOrigin-RevId: 450759214
  • Loading branch information
amalloy authored and Error Prone Team committed May 24, 2022
1 parent 81acea9 commit fbacd85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.errorprone.fixes.SuggestedFixes.qualifyType;
import static com.google.errorprone.matchers.Description.NO_MATCH;
import static com.google.errorprone.util.ASTHelpers.enclosingClass;
import static com.google.errorprone.util.ASTHelpers.getStartPosition;
import static com.google.errorprone.util.ASTHelpers.getSymbol;

import com.google.errorprone.BugPattern;
Expand All @@ -33,6 +34,7 @@
import com.sun.source.tree.MemberSelectTree;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.util.Position;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -64,6 +66,10 @@ public Description matchMemberSelect(MemberSelectTree tree, VisitorState state)
return NO_MATCH;
}
}
if (getStartPosition(tree) == Position.NOPOS) {
// Can't suggest changing a synthetic type tree
return NO_MATCH;
}
SuggestedFix.Builder fixBuilder = SuggestedFix.builder();
SuggestedFix fix =
fixBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ public void negative() {
.doTest();
}

@Test
public void qualifiedName_inLambdaParameter_cantFix() {
compilationHelper
.addSourceLines(
"Test.java",
"import java.util.function.Function;",
"class Test {",
" interface Rec extends Function<Rec, Rec> {}\n",
" void run() {",
" Rec f = x -> x.apply(x);",
" }",
"}")
.doTest();
}

@Test
public void qualifiedName_ambiguous() {
compilationHelper
Expand Down

0 comments on commit fbacd85

Please sign in to comment.