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 7049f5c21153..e44b18c3df5d 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 @@ -1449,16 +1449,14 @@ private static int compareModelVersions(String first, String second) { // we use a dedicated comparator because we control our model version scheme. String[] firstSegments = StringUtils.split(first, "."); String[] secondSegments = StringUtils.split(second, "."); - for (int i = 0; i < Math.min(firstSegments.length, secondSegments.length); i++) { - int result = Long.valueOf(firstSegments[i]).compareTo(Long.valueOf(secondSegments[i])); + for (int i = 0; i < Math.max(firstSegments.length, secondSegments.length); i++) { + int result = Long.valueOf(i < firstSegments.length ? firstSegments[i] : "0") + .compareTo(Long.valueOf(i < secondSegments.length ? secondSegments[i] : "0")); if (result != 0) { return result; } } - if (firstSegments.length == secondSegments.length) { - return 0; - } - return firstSegments.length > secondSegments.length ? -1 : 1; + return 0; } @SuppressWarnings("checkstyle:parameternumber") diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index e1419f467185..7c6081aae198 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -117,6 +117,15 @@ public void testBadModelVersion() throws Exception { assertTrue(result.getFatals().get(0).contains("modelVersion")); } + public void testModelVersion40() throws Exception { + SimpleProblemCollector result = + validateRaw("modelVersion-4_0.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT); + + assertViolations(result, 0, 1, 0); + + assertTrue(result.getErrors().get(0).contains("'modelVersion' must be one of")); + } + public void testMissingArtifactId() throws Exception { SimpleProblemCollector result = validate("missing-artifactId-pom.xml"); diff --git a/maven-model-builder/src/test/resources/poms/validation/modelVersion-4_0.xml b/maven-model-builder/src/test/resources/poms/validation/modelVersion-4_0.xml new file mode 100644 index 000000000000..544331b1f141 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/modelVersion-4_0.xml @@ -0,0 +1,25 @@ + + + + 4.0 + foo + bar + 0.1 +