You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Dale King (JIRA)" <ji...@apache.org> on 2019/04/15 21:47:00 UTC

[jira] [Commented] (MNG-4731) NPE from AttachedArtifact.getVersion rather than meaningful error

    [ https://issues.apache.org/jira/browse/MNG-4731?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16818416#comment-16818416 ] 

Dale King commented on MNG-4731:
--------------------------------

Re-reported as: https://issues.apache.org/jira/browse/MNG-6641

> NPE from AttachedArtifact.getVersion rather than meaningful error
> -----------------------------------------------------------------
>
>                 Key: MNG-4731
>                 URL: https://issues.apache.org/jira/browse/MNG-4731
>             Project: Maven
>          Issue Type: Bug
>          Components: Errors
>    Affects Versions: 2.2.1
>         Environment: Ubuntu Lucid, JDK 6u21
>            Reporter: Jesse Glick
>            Priority: Major
>         Attachments: validateIdentity.diff
>
>
> I am working on a problem with {{nbm:populate-repository}} (from {{org.codehaus.mojo:nbm-maven-plugin}}). Maven 2.2.1, when run under certain circumstances, fails when running this goal with the following unhelpful message:
> {noformat}
> ...
> [ERROR] FATAL ERROR
> [INFO] ------------------------------------------------------------------------
> [INFO] null
> [INFO] ------------------------------------------------------------------------
> [INFO] Trace
> java.lang.NullPointerException
> 	at org.apache.maven.project.artifact.AttachedArtifact.getVersion(AttachedArtifact.java:122)
> 	at org.apache.maven.artifact.DefaultArtifact.validateIdentity(DefaultArtifact.java:141)
> 	at org.apache.maven.artifact.DefaultArtifact.<init>(DefaultArtifact.java:122)
> 	at org.apache.maven.project.artifact.AttachedArtifact.<init>(AttachedArtifact.java:42)
> 	at org.codehaus.mojo.nbm.PopulateRepositoryMojo.createAttachedArtifact(PopulateRepositoryMojo.java:617)
> 	at org.codehaus.mojo.nbm.PopulateRepositoryMojo.execute(PopulateRepositoryMojo.java:424)
> ...
> {noformat}
> Inspection of the code reveals the immediate cause of the NPE: in {{getVersion}}, the {{parent}} field is null. Even though this is a final field set in the constructor to a non-null value, it has not yet been set when the super constructor is called. This is because {{DefaultArtifact}} uses the antipattern of calling an overridable method ({{getVersion}}) from its constructor (indirectly via {{validateIdentity}}). The NPE then prevents the details of the problem from being reported to the user.
> Ideally this antipattern would be solved, by making {{validateIdentity}} public and requiring all creators of a {{DefaultArtifact}} to call it after construction. Since this cannot now be done compatibly (e.g. {{PopulateRepositoryMojo}} above would need to be modified), the next best thing is to assume that {{AttachedArtifact}} is the only subclass, and ensure that {{validateIdentity}} is called only once the object has been fully constructed. With that change (patch against {{2.2.2-SNAPSHOT}} attached), the error message is informative (specifics of this run have been elided) and points toward possible problems in the plugin:
> {noformat}
> ...
> [ERROR] FATAL ERROR
> [INFO] ------------------------------------------------------------------------
> [INFO] An invalid artifact was detected.
> This artifact might be in your project's POM, or it might have been included transitively
> during the resolution process. Here is the information we do have for this artifact:
>     o GroupID:     ...
>     o ArtifactID:  ...
>     o Version:     ...
>     o Type:        <<< MISSING >>>
> [INFO] ------------------------------------------------------------------------
> [INFO] Trace
> org.apache.maven.artifact.InvalidArtifactRTException: For artifact {...:...:...:null}: The type cannot be empty.
> 	at org.apache.maven.artifact.DefaultArtifact.validateIdentity(DefaultArtifact.java:141)
> 	at org.apache.maven.project.artifact.AttachedArtifact.validateIdentity(AttachedArtifact.java:63)
> 	at org.apache.maven.project.artifact.AttachedArtifact.<init>(AttachedArtifact.java:53)
> 	at org.codehaus.mojo.nbm.PopulateRepositoryMojo.createAttachedArtifact(PopulateRepositoryMojo.java:617)
> 	at org.codehaus.mojo.nbm.PopulateRepositoryMojo.execute(PopulateRepositoryMojo.java:424)
> ...
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)