From 6da454eba9a050bf90be1d7e9f5e0c50968219db Mon Sep 17 00:00:00 2001 From: ghm Date: Thu, 21 Apr 2022 09:58:19 -0700 Subject: [PATCH] Fix the workaround for SimpleCharStream. PiperOrigin-RevId: 443406257 --- .../google/errorprone/bugpatterns/MixedArrayDimensions.java | 4 +++- .../errorprone/bugpatterns/MixedArrayDimensionsTest.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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(); }