RFR: 8298380: Clean up redundant array length checks in JDK code base

Sergey Tsypanov stsypanov at openjdk.org
Thu Dec 8 12:45:29 UTC 2022


Newer version of IntelliJ IDEA introduces new [inspection](https://youtrack.jetbrains.com/issue/IDEA-301797/IDEA-should-report-redundant-array-length-check-in-certain-cases) detecting redundant array length check in snippets like

<T> void iterate(T[] items) {
  if (items.length == 0) {
    return;
  }
  for (T item : items) {
    //...
  }
}

Here

if (items.length == 0) {
  return;
}

is redundant and can be removed as length check is performed by for-each loop.

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

Commit messages:
 - 8298380: Clean up redundant array length checks in JDK code base

Changes: https://git.openjdk.org/jdk/pull/11589/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11589&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8298380
  Stats: 51 lines in 8 files changed: 0 ins; 14 del; 37 mod
  Patch: https://git.openjdk.org/jdk/pull/11589.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11589/head:pull/11589

PR: https://git.openjdk.org/jdk/pull/11589


More information about the serviceability-dev mailing list