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

[java] ForLoopCanBeForeach should consider iterating on this #833

Closed
oowekyala opened this issue Jan 7, 2018 · 1 comment · Fixed by #3126
Closed

[java] ForLoopCanBeForeach should consider iterating on this #833

oowekyala opened this issue Jan 7, 2018 · 1 comment · Fixed by #3126
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@oowekyala
Copy link
Member

oowekyala commented Jan 7, 2018

Affects PMD Version: 6.0.0

Rule: ForLoopCanBeForeach

Description: The rule should report loops that are iterated on this if possible. For now it considers neither this.iterator() nor just iterator(). Followup on #800

Code Sample demonstrating the issue:

import java.util.Iterator;
class Foo<T> implements Iterable<T> {

  @Override
  public Iterator<T> iterator() {
    return null;
  }

  private void fofo() {
    for (Iterator<T> it = iterator(); it.hasNext();) {
      T item = it.next();
    }
    for (Iterator<T> it = this.iterator(); it.hasNext();) {
      T item = it.next();
    }
  }
}

Running PMD through: CLI

@oowekyala oowekyala added the a:false-negative PMD doesn't flag a problematic piece of code label Jan 7, 2018
@jsotuyod jsotuyod added this to the 6.1.0 milestone Jan 8, 2018
@adangel adangel modified the milestones: 6.1.0, 6.2.0 Feb 25, 2018
@adangel adangel modified the milestones: 6.2.0, 6.3.0 Mar 26, 2018
@adangel adangel modified the milestones: 6.3.0, 6.4.0 Apr 28, 2018
@oowekyala oowekyala modified the milestones: 6.4.0, 6.5.0 May 19, 2018
@jsotuyod jsotuyod modified the milestones: 6.5.0, 6.6.0 Jun 26, 2018
@adangel adangel modified the milestones: 6.6.0, 6.7.0 Jul 29, 2018
@adangel adangel modified the milestones: 6.7.0, 6.8.0 Sep 1, 2018
@oowekyala oowekyala removed this from the 6.8.0 milestone Sep 29, 2018
@oowekyala oowekyala added this to the 7.0.0 milestone Nov 5, 2020
oowekyala added a commit to oowekyala/pmd that referenced this issue Feb 19, 2021
Fixes pmd#833

Remove unresolved things from tests
oowekyala added a commit to oowekyala/pmd that referenced this issue Mar 8, 2021
@oowekyala oowekyala linked a pull request Mar 8, 2021 that will close this issue
5 tasks
adangel added a commit that referenced this issue Mar 26, 2021
@adangel adangel mentioned this issue Jan 23, 2023
55 tasks
@adangel
Copy link
Member

adangel commented Apr 22, 2023

This has been fixed with PMD 7.0.0-rc1.

@adangel adangel closed this as completed Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants