RFR: 7903538: NullPointerException: Cannot read the array length because "<local9>" is null

Jaikiran Pai jpai at openjdk.org
Tue Mar 5 06:31:54 UTC 2024


Can I please get a review for this change which proposes to fix the issue noted in https://bugs.openjdk.org/browse/CODETOOLS-7903538?

`java.io.File.listFiles()` as per its API doc says:

> ... Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

So return values from `File.listFiles()` require a null check. It looks like this missing null check, in the `for` loop of the code being changed here, was in fact noticed previously and an attempt to address that was made almost a decade back in https://github.com/openjdk/jtreg/commit/329d3fb3dd6ab31c7133ef95383068f2de6f7735. But I think there's an oversight in that change. It does introduce a `null` check for the return value, but it still goes on to again call `dir.listFiles()` in the `for` loop. `dir` doesn't change ever in the `for` loop nor in that `else` block, so the `for` loop should just have used the `children` variable which is guaranteed to be non-null at that point.

The commit in this PR addresses that oversight. No new tests have been included given the nature of this change. Existing tests continue to pass.

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

Commit messages:
 - 7903538: NullPointerException: Cannot read the array length because "<local9>" is null

Changes: https://git.openjdk.org/jtreg/pull/186/files
 Webrev: https://webrevs.openjdk.org/?repo=jtreg&pr=186&range=00
  Issue: https://bugs.openjdk.org/browse/CODETOOLS-7903538
  Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jtreg/pull/186.diff
  Fetch: git fetch https://git.openjdk.org/jtreg.git pull/186/head:pull/186

PR: https://git.openjdk.org/jtreg/pull/186


More information about the jtreg-dev mailing list