Skip to content

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

Open

Description

@elharo

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.

Activity

  1. added
    bug
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions