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 ForEachIterable error when calling iterator method without 'this' #2260

Closed

Conversation

AndrewMonteith
Copy link
Contributor

Problem

The ForEachIterable check will NPE when generating a fix for an instance where the method returning the iterator is a member function, (ie called with this as the receiver). This causes getReceiver to return null, as expected, but then will trigger a NPE from state.getSourceForNode. The other two cases getReceiver can return null are for static methods, this will never occur though since the earlier ITERATOR matcher does not match static methods.

PR Contribution

If getReceiver returns null then the fix will iterate over 'this' since getReceiver is returning null for getReceiver(this.iterator()) so in reality should return this. The new case, and associated fix, can be seen in the unit test.

@google-cla google-cla bot added the cla: yes label Mar 31, 2021
@AndrewMonteith AndrewMonteith deleted the fix_for_each_iterable branch April 24, 2021 14:36
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

2 participants