diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MixedArrayDimensions.java b/core/src/main/java/com/google/errorprone/bugpatterns/MixedArrayDimensions.java index b971c4ee085..4c0bd66e7fa 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MixedArrayDimensions.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MixedArrayDimensions.java @@ -18,6 +18,7 @@ import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; import static com.google.errorprone.matchers.Description.NO_MATCH; +import static com.google.errorprone.util.ASTHelpers.enclosingClass; import static com.google.errorprone.util.ASTHelpers.getSymbol; import com.google.common.base.CharMatcher; @@ -74,7 +75,8 @@ private Description checkArrayDimensions(Tree tree, Tree type, VisitorState stat if (idx > nonWhitespace) { String replacement = dim.substring(idx) + dim.substring(0, idx); // SimpleCharStream generates violations in other packages, and is challenging to fix. - if (getSymbol(tree).owner.name.contentEquals("SimpleCharStream")) { + var enclosingClass = enclosingClass(getSymbol(tree)); + if (enclosingClass != null && enclosingClass.name.contentEquals("SimpleCharStream")) { return NO_MATCH; } return describeMatch(tree, SuggestedFix.replace(start, end, replacement)); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MixedArrayDimensionsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MixedArrayDimensionsTest.java index f628c10a3fa..c7ded2d64f5 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MixedArrayDimensionsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MixedArrayDimensionsTest.java @@ -94,7 +94,9 @@ public void negativeInSimpleCharStream() { .addSourceLines( "SimpleCharStream.java", // "final class SimpleCharStream {", - " int a[];", + " void test() {", + " int a[];", + " }", "}") .doTest(); }