Potential NPE in SelectJdkToolchainMojo.getJdkHome() from unchecked null chain

Open Beginner friendly
#168 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java

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.

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

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:

&& 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.

Dominant language
Java
Stars
27
Forks
31
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/maven-toolchains-plugin

All issues in apache/maven-toolchains-plugin

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.