Skip to content

Handle pomTarget without a parent directory (#169) - #174

Open
elharo wants to merge 2 commits into
masterfrom
fix/issue-169-createpom-npe
Open

Handle pomTarget without a parent directory (#169)#174
elharo wants to merge 2 commits into
masterfrom
fix/issue-169-createpom-npe

Conversation

@elharo

@elharo elharo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #169

Problem

CreatePom.execute() threw a NullPointerException when pomTarget was a bare relative filename such as pom.xml. For such a value new File("pom.xml").getParentFile() returns null, so the parent-dir check failed.

Fix

Resolve a bare pomTarget against the Ant project base dir before creating the parent directory. The POM is now written to ${basedir}/pom.xml, matching the expected behavior of writing to the current working directory / project base dir. Targets with a directory component (e.g. out/pom.xml) behave as before.

Test

New CreatePomNoParentDirTest unit test reproduces the crash: it runs the task with pomTarget="pom.xml" and a project base dir, and asserts the POM is written to ${basedir}/pom.xml. Before the fix it fails with the NPE above; after the fix it passes.

All 55 tests pass (mvn verify).

CreatePom.execute() threw a NullPointerException when pomTarget was a
bare relative filename such as 'pom.xml', because new File('pom.xml')
returns null from getParentFile().  Resolve a bare pomTarget against the
project base dir before creating the parent directory, so the POM is
written to the Ant project base dir.
@elharo elharo added the bug Something isn't working label Aug 4, 2026
@elharo
elharo marked this pull request as draft August 6, 2026 11:28
@elharo

elharo commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

The CI failure was in the Ant smoke-test target (build.xml:98), which uses a JUnit 3-style <junit> batch run: it reported No tests found in CreatePomNoParentDirTest and failed the build.

The test class was missing the public static junit.framework.Test suite() method that every other test class provides (see CreatePomTest, CreatePomRainyDayTest, etc.) so the Ant runner could not discover its tests.

Added the suite() method backed by JUnit4TestAdapter (plus the required junit.framework.JUnit4TestAdapter import). Verified with mvn -Prun-its verify: the smoke-test now runs CreatePomNoParentDirTest (1 test, 0 failures) and the full build passes.

@elharo
elharo marked this pull request as ready for review August 7, 2026 11:09
@elharo
elharo requested a review from slawekjaranowski August 7, 2026 11:09
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.

CreatePom throws NullPointerException when pomTarget has no parent directory

1 participant