Integrated: 7903538: NullPointerException: Cannot read the array length because "<local9>" is null
Jaikiran Pai
jpai at openjdk.org
Wed Mar 20 05:20:31 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.
This pull request has now been integrated.
Changeset: c1ef5004
Author: Jaikiran Pai <jpai at openjdk.org>
Committer: Christian Stein <cstein at openjdk.org>
URL: https://git.openjdk.org/jtreg/commit/c1ef50048f963e5c99c9b00188e633f4c7fba8bc
Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod
7903538: NullPointerException: Cannot read the array length because "<local9>" is null
Reviewed-by: cstein, jjg
-------------
PR: https://git.openjdk.org/jtreg/pull/186
More information about the jtreg-dev
mailing list