Skip to content

Use of AvailableJavaHomes causes NPEs when environment is not ready #35766

@alllex

Description

@alllex

The AvailableJavaHomes is used extensively in tests that validate Java Toolchain features or in other tests that require toolchains.

There is a disconnect between how the fixture is written and how it is used. The majority of uses for fixture calls expect a resolved JDK or JVM location, which is then used to obtain an executable path or other metadata. However, most methods on the fixture are written such that they return null if an appropriate JDK is not found.

This results in not immediately clear errors, when trying to run tests locally without having the local environment being prepared for it, i.e. without having necessary JDK installations. This creates friction for Gradle developers as well as external contributors.

Proposal: update the AvailableJavaHomes fixture such that its methods fail with an actionable error, when a requested JDK is not found.

There are still cases when leniency is expected, but those are rare, so they can use methods that are more explicit, like getDifferentJdkOrNull().

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions