RFR: 8274237: Replace 'for' cycles with iterator with enhanced-for in java.base

Daniel Fuchs dfuchs at openjdk.java.net
Fri Sep 24 10:30:51 UTC 2021


On Thu, 23 Sep 2021 20:42:48 GMT, Andrey Turbanov <github.com+741251+turbanoff at openjdk.org> wrote:

> There are few places in code where manual `for` loop is used with Iterator to iterate over Collection.
> Instead of manual `for` cycles it's preferred to use enhanced-for cycle instead: it's less verbose, makes code easier to read and it's less error-prone.
> Sometimes we even don't need cycle at all: we can just create one ArrayList as a copy of another.
> It doesn't have any performance impact: java compiler generates similar code when compiling enhanced-for cycle.
> This is continuation of [JDK-8273261](https://bugs.openjdk.java.net/browse/JDK-8273261)

Looks good to me in general. Changes to `sun.net` look very good. Thanks for the simplification!
Please have someone from security-dev give approval before integrating.

-------------

Marked as reviewed by dfuchs (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/5665



More information about the security-dev mailing list