Skip to content

fix: prevent NPE in ManifestConfiguration.getClasspathPrefix() when prefix is null - #381

Merged
elharo merged 1 commit into
apache:masterfrom
elharo:fix-367-npe-classpath-prefix
Aug 4, 2026
Merged

fix: prevent NPE in ManifestConfiguration.getClasspathPrefix() when prefix is null#381
elharo merged 1 commit into
apache:masterfrom
elharo:fix-367-npe-classpath-prefix

Conversation

@elharo

@elharo elharo commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #367.

Problem: ManifestConfiguration.getClasspathPrefix() calls .replaceAll() on the field without a null check. The field is initialized to "", but the setter stores the value as-is. If any caller passes null (e.g., from unset XML configuration elements mapped via Plexus), the getter throws NPE.

Fix: Guard setClasspathPrefix() against null, falling back to "".

Test: Added getClasspathPrefixShouldHandleNull().

…refix is null

The setter now treats null as the empty string, consistent with the field's
default value. This prevents a NullPointerException in getClasspathPrefix()
when callers pass null (e.g., from unset XML configuration elements).

Fixes apache#367
@elharo
elharo force-pushed the fix-367-npe-classpath-prefix branch from dbe9d8c to ac18752 Compare July 4, 2026 13:06
@elharo elharo added the bug Something isn't working label Aug 4, 2026

@ascheman ascheman left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The NPE came from the setter storing a caller's null as-is, which then hit getClasspathPrefix()'s replaceAll. Guarding it in the setter (null → "") is the right layer — it restores the field's non-null invariant (it already defaults to ""), so the getter is always safe, and getClasspathPrefix() is the only getter here that manipulates the string, so no sibling field is left exposed. The added getClasspathPrefixShouldHandleNull() test locks it in. Thanks @elharo.

@elharo
elharo merged commit 3b674cd into apache:master Aug 4, 2026
8 checks passed
@github-actions github-actions Bot added this to the 4.0.0-beta-5 milestone Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE in ManifestConfiguration.getClasspathPrefix() when prefix is set to null

2 participants