Skip to content

Remove unreachable null check from BuildClasspathMojo - #1666

Open
wilx wants to merge 1 commit into
apache:masterfrom
wilx:issue-1648-build-classpath-null
Open

Remove unreachable null check from BuildClasspathMojo#1666
wilx wants to merge 1 commit into
apache:masterfrom
wilx:issue-1648-build-classpath-null

Conversation

@wilx

@wilx wilx commented Aug 1, 2026

Copy link
Copy Markdown

getResolvedDependencies(true) supplies a non-null Set; projects with no resolved dependencies receive an empty set. Remove the misleading artifacts == null condition from BuildClasspathMojo while retaining the existing empty-set logging and empty classpath output.

This aligns the Mojo with the dependency resolver's effective contract. Because the null case cannot be produced through the supported Maven dependency-resolution path, no defensive conversion or null-specific test is needed.

Fixes #1648.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
    This is not a behavioral change: the null branch is unreachable, and the existing empty-set behavior is unchanged.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@wilx
wilx marked this pull request as ready for review August 1, 2026 16:54

@elharo elharo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

needs a test

@@ -198,7 +199,10 @@ protected void doExecute() throws MojoExecutionException {

Set<Artifact> artifacts = getResolvedDependencies(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can this method return null? what's it's contract? and if it can return null, should it be changed to return an empty set instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not in the current Maven, I think. But I did not study all the versions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the method marked nullable or non-nullable?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It is not marked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see an issue here. If the method doesn;t return null, it doesn't return null.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have removed the check and reworded the commit.

@wilx wilx changed the title Avoid NPE when building an empty classpath Remove unreachable null check from BuildClasspathMojo Aug 2, 2026
Rely on getResolvedDependencies(boolean) to return a non-null set while retaining the existing empty-set handling.

Fixes apache#1648.
@wilx
wilx force-pushed the issue-1648-build-classpath-null branch from 409ed09 to a94714a Compare August 2, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE in BuildClasspathMojo when getResolvedDependencies returns null

2 participants