Skip to content

Commit

Permalink
Fix a crash in NonCanonicalType with type annotations
Browse files Browse the repository at this point in the history
Fixes #4343

PiperOrigin-RevId: 618890911
  • Loading branch information
cushon authored and Error Prone Team committed Mar 25, 2024
1 parent cd6a504 commit af9dad8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -29,6 +29,7 @@
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.Visibility;
import com.sun.source.tree.AnnotatedTypeTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.Tree;
Expand Down Expand Up @@ -135,6 +136,8 @@ private static String getNonCanonicalName(Tree tree) {
+ memberSelectTree.getIdentifier();
case PARAMETERIZED_TYPE:
return getNonCanonicalName(((ParameterizedTypeTree) tree).getType());
case ANNOTATED_TYPE:
return getNonCanonicalName(((AnnotatedTypeTree) tree).getUnderlyingType());
default:
throw new AssertionError(tree.getKind());
}
Expand Down
Expand Up @@ -254,4 +254,27 @@ public void moduleInfo() {
"}")
.doTest();
}

// https://github.com/google/error-prone/issues/4343
@Test
public void typeAnnotation() {
compilationHelper
.addSourceLines(
"Crash.java",
"import java.lang.annotation.ElementType;",
"import java.lang.annotation.Target;",
" @Target(ElementType.TYPE_USE)",
" @interface TA {}",
" class Crash {",
" class Nested {",
" class DoublyNested {}",
" }",
" class SubNested extends Nested {",
" }",
" void foo(Crash.@TA Nested.DoublyNested p) {}",
" // BUG: Diagnostic contains: Crash.Nested.DoublyNested",
" void bar(Crash.@TA SubNested.DoublyNested p) {}",
" }")
.doTest();
}
}

0 comments on commit af9dad8

Please sign in to comment.