Skip to content

Avoid NPE in isArtifactRegistered when module artifact is null #519 - #549

Merged
elharo merged 4 commits into
apache:masterfrom
AzazelSensei:fix/519-null-artifact-registered
Aug 30, 2026
Merged

Avoid NPE in isArtifactRegistered when module artifact is null #519#549
elharo merged 4 commits into
apache:masterfrom
AzazelSensei:fix/519-null-artifact-registered

Conversation

@AzazelSensei

@AzazelSensei AzazelSensei commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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.
  • 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).

EarModule.getArtifact() is documented as null until the module is resolved. isArtifactRegistered called equals on that value, so a null artifact threw NPE.

execute() always resolves user modules first, so that path does not reach an unresolved module. I flipped the comparison to artifact.equals(em.getArtifact()) so a null module artifact still does not NPE.

EarModule.getArtifact() is null until resolveArtifact runs. The stream
used null.equals(artifact) and blew up. Treat a missing artifact as not
registered.

private static boolean isArtifactRegistered(Artifact a, List<EarModule> currentList) {
return currentList.stream().anyMatch(em -> em.getArtifact().equals(a));
static boolean isArtifactRegistered(Artifact a, List<EarModule> currentList) {

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.

a --> artifact

@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Renamed the parameter to artifact.

return currentList.stream().anyMatch(em -> em.getArtifact().equals(a));
static boolean isArtifactRegistered(Artifact artifact, List<EarModule> currentList) {
return currentList.stream()
.anyMatch(em -> em.getArtifact() != null && em.getArtifact().equals(artifact));

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.

Check me but I think this is simpler if you just flip the comparison:

em -> artifact.equals(em.getArtifact())

@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Flipped the comparison to artifact.equals(em.getArtifact()).

class AbstractEarMojoTest extends AbstractEarTestBase {

@Test
void isArtifactRegisteredSkipsUnresolvedModule() {

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'm not fond of testing what are effectively private methods made non-private only for a test. Is there any way to test this through the public API? Maybe with an integration test? If there's no observable difference without using private access, there might not actually be a problem.

execute() always resolves user modules first, so a unit test of the
helper was not a public-API repro. Keep artifact.equals so a null
getArtifact() still does not NPE.
@AzazelSensei

Copy link
Copy Markdown
Contributor Author

execute() always calls resolveArtifact on user modules before this check, so an unresolved module never reaches it. I dropped the unit test and made the helper private again. Left artifact.equals so a null getArtifact() still does not NPE.

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

since it no longer skips, PR description and title should be updated

@AzazelSensei AzazelSensei changed the title Skip unresolved modules in isArtifactRegistered #519 Avoid NPE in isArtifactRegistered when module artifact is null #519 Aug 29, 2026
@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Updated the title and description to match the equals flip.

@elharo
elharo merged commit 121d321 into apache:master Aug 30, 2026
17 checks passed
@github-actions

Copy link
Copy Markdown

@elharo Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 3.4.1 milestone Aug 30, 2026
@elharo elharo added the bug Something isn't working label Aug 30, 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.

2 participants