RFR: 7903538: NullPointerException: Cannot read the array length because "<local9>" is null
Jaikiran Pai
jpai at openjdk.org
Fri Mar 15 07:06:52 UTC 2024
On Tue, 5 Mar 2024 06:27:34 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:
> 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.
Thank you Christian for the review. Can some Reviewer too review this please?
-------------
PR Comment: https://git.openjdk.org/jtreg/pull/186#issuecomment-1999055700
More information about the jtreg-dev
mailing list