Skip to content

Commit ab06403

Browse files
committed
Don't crash when trying to qualify ambiguous simple names
Discovered while validating 2.4.0 release (#1639) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=313496085
1 parent b83a2b4 commit ab06403

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ public static String qualifyType(VisitorState state, SuggestedFix.Builder fix, S
381381
// Check if the simple name is already visible.
382382
String simpleName = Iterables.getLast(components);
383383
Symbol simpleNameSymbol = FindIdentifiers.findIdent(simpleName, state, KindSelector.VAL_TYP);
384-
if (simpleNameSymbol != null && simpleNameSymbol.getQualifiedName().contentEquals(typeName)) {
384+
if (simpleNameSymbol != null
385+
&& !simpleNameSymbol.getKind().equals(ElementKind.OTHER)
386+
&& simpleNameSymbol.getQualifiedName().contentEquals(typeName)) {
385387
return simpleName;
386388
}
387389

core/src/test/java/com/google/errorprone/bugpatterns/NonCanonicalTypeTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,29 @@ public void negative() {
126126
"}")
127127
.doTest();
128128
}
129+
130+
@Test
131+
public void qualifiedName_ambiguous() {
132+
compilationHelper
133+
.addSourceLines(
134+
"Test.java",
135+
"interface A {",
136+
" interface N {}",
137+
"}",
138+
"interface B extends A {}",
139+
"class C implements D {}",
140+
"interface E extends D {",
141+
" interface N extends D.N {}",
142+
"}",
143+
"interface D {",
144+
" interface N {}",
145+
"}",
146+
"class Test extends C implements E {",
147+
" // BUG: Diagnostic contains: A.N",
148+
" private B.N f() {",
149+
" return null;",
150+
" }",
151+
"}")
152+
.doTest();
153+
}
129154
}

0 commit comments

Comments
 (0)