maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Miller (JIRA)" <>
Subject [jira] Commented: (MNG-4047) NPE in resolver if artifact defined with a version range
Date Mon, 23 Mar 2009 14:19:12 GMT


Alex Miller commented on MNG-4047:

I got the same behavior with 2.0.10.  Due to how integrated the code was with the Terracotta
source base (and the fact that I couldn't check it in), I don't really have any sample project/command
that illustrated the problem.  I ended up concluding from the code that while DefaultArtifactResolver
takes an Artifact it (implicitly) assumes that that Artifact (which may have a version range
spec) has already been constrained in the VersionRange instance to a specific version (using
restrict()).  The ArtifactResolver does not seem to have logic to resolve the "best" version
from a set of possible versions in the repository.

However, I did find that the ArtifactCollector seemed to be intended for that purpose (javadoc:
 "takes a set of original artifacts and resolves all of the best versions to use along with
their metadata")  so I have reworked the code to use the collector instead.  I now use the
ArtifactCollector to resolve the best version of the artifact in the range and then use the
resolver on the specific version, something like:

      ArtifactResolutionResult result = artifactCollector.collect(artifacts, originatingArtifact,
localRepository, remoteRepositories, metadataSource, null, Collections.EMPTY_LIST);
      Set nodes = result.getArtifactResolutionNodes();
      ResolutionNode resultNode = (ResolutionNode) nodes.iterator().next();
      selectedArtifact = resultNode.getArtifact();
      artifactResolver.resolve(selectedArtifact, remoteRepositories, localRepository);
      return selectedArtifact.getFile();

That code is making the assumption that nodes contains a single result.  That happens to be
guaranteed for me as I control the repository and the version that exists but may not generally
be a solution.

In short, I don't think that my original problem needs to be fixed, although it would be nice
if the DefaultArtifactResolver could understand the situation enough to tell me that it doesn't
support an unrestricted VersionRange rather than throwing an NPE.     

> NPE in resolver if artifact defined with a version range
> --------------------------------------------------------
>                 Key: MNG-4047
>                 URL:
>             Project: Maven 2
>          Issue Type: Bug
>          Components: Artifacts and Repositories
>    Affects Versions: 2.0.9
>         Environment: Mac OS X, Maven 2.0.9
>            Reporter: Alex Miller
>             Fix For: 2.1.x
>         Attachments: out.txt
> I'm seeing the following NPE when calling the ArtifactResolver with an Artifact defined
by a VersionRange.  Here the version for this artifact is defined as "[1.0.0-SNAPSHOT,1.1.0-SNAPSHOT)"
and the 1.0.0-SNAPSHOT artifact is in my local repository.  
> java.lang.NullPointerException: version was null for org.terracotta:terracotta-test-api
>         at org.apache.maven.artifact.DefaultArtifact.getBaseVersion(
>         at org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout.pathOf(
>         at org.apache.maven.artifact.repository.DefaultArtifactRepository.pathOf(
>         at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(
>         at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(
>         at
>         at
>         at
>         at
>         at org.apache.maven.plugin.DefaultPluginManager.executeMojo(
> The tc-maven-plugin source can be perused here:

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


View raw message