From eeeee178216a6d47b752b57a53f81ac5f8e1d8d8 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 17 Sep 2009 10:46:52 +0000 Subject: [PATCH] o Fixed inconsistent behavior of version getters git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@816133 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/artifact/DefaultArtifact.java | 7 ++----- .../org/apache/maven/artifact/DefaultArtifactTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) 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() ); + } + }