apache / apache/maven-toolchains-plugin
Potential NPE in SelectJdkToolchainMojo.getJdkHome() from unchecked null chain
- Dominant language
- Java
- Stars
- 27
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
## Summary
The `getJdkHome()` method in `SelectJdkToolchainMojo` has an unchecked null chain that can throw a `NullPointerException`. The equivalent method in `ToolchainMojo` correctly guards against nulls.
## Location
`SelectJdkToolchainMojo.java:264-268`
```java
private String getJdkHome(ToolchainPrivate toolchain) {
return ((Xpp3Dom) toolchain.getModel().getConfiguration())
.getChild("jdkHome")
.getValue();
}
```
## Problem
Each call in the chain can return null without a guard:
1. `toolchain.getModel()` could return null
2. `getModel().getConfiguration()` could return null (causing NPE on the cast)
3. `(Xpp3Dom)` cast itself could throw `ClassCastException` if configuration is not `Xpp3Dom`
4. `.getChild("jdkHome")` could return null
5. `.getValue()` on null would throw NPE
Compare with the properly guarded version in `ToolchainMojo`.
## Impact
Can cause NPE during `IfSame` mode execution, specifically on this line:
```java
&& Objects.equals(getJdkHome(currentJdkToolchain), getJdkHome(toolchain)))
```
## Suggested Fix
Add null guards matching the pattern used in `ToolchainMojo`, or better yet, reuse that method by extracting it to a shared utility.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at SelectJdkToolchainMojo.java:264-268 and compare getJdkHome() with the guarded equivalent in ToolchainMojo. Verify the IfSame-mode call no longer throws for missing model, configuration, or jdkHome data, while preserving the existing JDK-home lookup behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100