apache / apache/maven

[MNG-6641] NPE from AttachedArtifact.getVersion rather than meaningful error

Open
#8,393 2 comments 0 reactions 0 assignees View on GitHub
bug priority:minor
Dominant language
Java
Stars
5.3k
Forks
3.1k
Avg merge
20h 42m
Merged PRs (30d)
297

Description

**[Dale King](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=dalewking)** opened **[MNG-6641](https://issues.apache.org/jira/browse/MNG-6641?redirect=false)** and commented

This issue is basically re-reporting issue https://issues.apache.org/jira/browse/MNG-4731, which was closed in the great Jira clean up of 2014. 5 years later I can report it is still an issue.

The issue occurs when the information passed to AttachedArtifact violates any of the validations in DefaultArtifact.validateIdentity(). The call to getVersion() will throw an NPE because it is overridable in the DefaultArtifact and parent has not been initialized yet in AttachedArtifact. MNG-4731 explains this more clearly.

A comment on that ticket suggests that the problem is that AttachedArtifact was called directly instead of using MavenProjectHelper.attachArtifact(). That is not true as can be seen from my stack trace:

```
Caused by: java.lang.NullPointerException
at org.apache.maven.project.artifact.AttachedArtifact.getVersion (AttachedArtifact.java:138)
at org.apache.maven.artifact.DefaultArtifact.validateIdentity (DefaultArtifact.java:149)
at org.apache.maven.artifact.DefaultArtifact. (DefaultArtifact.java:124)
at org.apache.maven.project.artifact.AttachedArtifact. (AttachedArtifact.java:49)
at org.apache.maven.project.DefaultMavenProjectHelper.attachArtifact (DefaultMavenProjectHelper.java:63)
at org.apache.maven.plugins.source.AbstractSourceJarMojo.packageSources (AbstractSourceJarMojo.java:324)
at org.apache.maven.plugins.source.AbstractSourceJarMojo.packageSources (AbstractSourceJarMojo.java:253)
at org.apache.maven.plugins.source.AbstractSourceJarMojo.execute (AbstractSourceJarMojo.java:216)
```

---

**Affects:** 3.6.0

**Issue Links:**
- [MNG-4731](https://issues.apache.org/jira/browse/MNG-4731) NPE from AttachedArtifact.getVersion rather than meaningful error
(_**"duplicates"**_)

0 votes, 6 watchers

Contributor guide

Open the contributing guide

Research direction

Start by reading AttachedArtifact.java and DefaultArtifact.java, following the validation path from DefaultMavenProjectHelper.attachArtifact shown in the stack trace. Reproduce the invalid-identity case and verify that it reports a meaningful validation error instead of an NPE from AttachedArtifact.getVersion().

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.