From e49d091bc4ff310dafbf824e7f304abb4517ce64 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Wed, 17 Aug 2011 11:02:03 +0000 Subject: [PATCH] [MNG-5157] NPE stemming from DefaultModelBuilder.containsCoordinates git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1158623 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/model/building/DefaultModelBuilder.java | 12 ++++++++++-- .../model/validation/DefaultModelValidator.java | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 2eab12bf18..093305c8d3 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -909,6 +909,13 @@ public class DefaultModelBuilder String artifactId = dependency.getArtifactId(); String version = dependency.getVersion(); + if ( version == null || version.length() <= 0 ) + { + problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.version' for " + + dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null ); + continue; + } + String imported = groupId + ':' + artifactId + ':' + version; if ( importIds.contains( imported ) ) @@ -1045,8 +1052,9 @@ public class DefaultModelBuilder private boolean containsCoordinates( String message, String groupId, String artifactId, String version ) { - return message != null && message.contains( groupId ) && message.contains( artifactId ) - && message.contains( version ); + return message != null && ( groupId == null || message.contains( groupId ) ) + && ( artifactId == null || message.contains( artifactId ) ) + && ( version == null || message.contains( version ) ); } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index eb83ba04bc..7e87df3072 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -356,6 +356,12 @@ public class DefaultModelValidator { String key = dependency.getManagementKey(); + validateStringNotEmpty( prefix + ".groupId", problems, Severity.ERROR, dependency.getGroupId(), key, + dependency ); + + validateStringNotEmpty( prefix + ".artifactId", problems, Severity.ERROR, dependency.getArtifactId(), key, + dependency ); + if ( "import".equals( dependency.getScope() ) ) { if ( !"pom".equals( dependency.getType() ) )