RFR: 7903538: NullPointerException: Cannot read the array length because "<local9>" is null [v2]
Jaikiran Pai
jpai at openjdk.org
Wed Mar 20 01:59:43 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.
Jaikiran Pai has updated the pull request incrementally with one additional commit since the last revision:
Jon's review - update code comment
-------------
Changes:
- all: https://git.openjdk.org/jtreg/pull/186/files
- new: https://git.openjdk.org/jtreg/pull/186/files/53b143d9..47ef17b5
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jtreg&pr=186&range=01
- incr: https://webrevs.openjdk.org/?repo=jtreg&pr=186&range=00-01
Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 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