diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java index e28709477c..c507aad6aa 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java @@ -357,14 +357,11 @@ public class DefaultArtifact public String getBaseVersion() { - if ( baseVersion == null ) + if ( baseVersion == null && version != null ) { - if ( version == null ) - { - throw new NullPointerException( "version was null for " + groupId + ":" + artifactId ); - } setBaseVersionInternal( version ); } + return baseVersion; } diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java index 7344d6d2bd..fbd0119161 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java @@ -127,4 +127,14 @@ public class DefaultArtifactTest assertTrue( artifact.compareTo( artifact1 ) == 0 ); assertTrue( artifact1.compareTo( artifact ) == 0 ); } + + public void testNonResolvedVersionRangeConsistentlyYieldsNullVersions() + throws Exception + { + VersionRange vr = VersionRange.createFromVersionSpec( "[1.0,2.0)" ); + artifact = new DefaultArtifact( groupId, artifactId, vr, scope, type, null, artifactHandler ); + assertEquals( null, artifact.getVersion() ); + assertEquals( null, artifact.getBaseVersion() ); + } + }