Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in MutablePublicArray check #1586

Closed
wants to merge 1 commit into from
Closed

Fix NPE in MutablePublicArray check #1586

wants to merge 1 commit into from

Conversation

Preston4tw
Copy link
Contributor

The MutablePublicArray check throws a NPE when examining
an array that's initialized during a static init block. Add a test case
and null checks.

The MutablePublicArray check throws a NPE when examining
an array that's initialized during a static init block. Add a test case
and null checks.
@Preston4tw
Copy link
Contributor Author

I'm a fairly inexperienced Java developer and it's not obvious if there's a better fix for the new test, but the PR as-is passes all the existing test cases in addition to the newly added one.

@@ -67,7 +67,7 @@ private static boolean nonEmptyArrayMatcher(VariableTree arrayExpression, Visito
return false;
}
JCNewArray newArray = (JCNewArray) arrayExpression.getInitializer();
if (!newArray.getDimensions().isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I suggest just doing the null-check here, instead of having to repeat it below:

    if (newArray == null) {
      return false;
    }

(I can make that edit when importing the PR, this is just an FYI.)

@cushon cushon self-assigned this May 12, 2020
@kluever kluever mentioned this pull request May 13, 2020
kluever pushed a commit that referenced this pull request May 13, 2020
The MutablePublicArray check throws a NPE when examining
an array that's initialized during a static init block. Add a test case

Fixes #1586

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=311230609
kluever pushed a commit that referenced this pull request May 13, 2020
The MutablePublicArray check throws a NPE when examining
an array that's initialized during a static init block. Add a test case

Fixes #1586

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=311230609
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants