Skip to content

Commit

Permalink
Fix a CCE in MutablePublicArray
Browse files Browse the repository at this point in the history
Discovered while validating 2.4.0 release (#1639)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=313488001
  • Loading branch information
cushon committed May 29, 2020
1 parent 16b25b4 commit 456716b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.errorprone.bugpatterns.BugChecker.VariableTreeMatcher;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.tree.VariableTree;
import com.sun.tools.javac.tree.JCTree.JCLiteral;
Expand Down Expand Up @@ -66,10 +67,11 @@ private static boolean nonEmptyArrayMatcher(VariableTree arrayExpression, Visito
if (!isArrayType().matches(arrayExpression, state)) {
return false;
}
JCNewArray newArray = (JCNewArray) arrayExpression.getInitializer();
if (newArray == null) {
ExpressionTree initializer = arrayExpression.getInitializer();
if (!(initializer instanceof JCNewArray)) {
return false;
}
JCNewArray newArray = (JCNewArray) initializer;
if (!newArray.getDimensions().isEmpty()) {
return newArray.getDimensions().stream()
.allMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,17 @@ public void publicStaticFinalStaticInitializeBlock() {
"}")
.doTest();
}

@Test
public void notAnArray() {
compilationHelper
.addSourceLines(
"Test.java",
"class Test {",
" // BUG: Diagnostic contains: MutablePublicArray",
" public static final long[] y = {0};",
" public static final long[] l = y;",
"}")
.doTest();
}
}

0 comments on commit 456716b

Please sign in to comment.