You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/10/14 07:52:44 UTC
(maven) branch maven-4.0.x updated: fix: accept documented lowercase values for maven.resolver.validation
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-4.0.x by this push:
new 56dc5341d7 fix: accept documented lowercase values for maven.resolver.validation
56dc5341d7 is described below
commit 56dc5341d75133ff70572c84f25037141fd24ed9
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Oct 14 09:52:37 2026 +0200
fix: accept documented lowercase values for maven.resolver.validation
Backport of #13407 to `maven-4.0.x`.
The property is documented as accepting `default`, `mild`, and `off`, but `MavenValidatorFactory` used `ConfigUtils.getEnum()` / `Enum.valueOf()` which is case-sensitive — so `-Dmaven.resolver.validation=mild` failed with an `IllegalArgumentException`.
- Parse the value ignoring case and surrounding whitespace, so both the documented lowercase values and the uppercase equivalents are accepted
- Report unknown values with the property name and the list of supported values
- Add `MavenValidatorFactoryTest` with parameterized tests covering case variants and the error message (4 of 5 tests fail without the fix)
---
impl/maven-impl/pom.xml | 5 ++
.../resolver/validator/MavenValidatorFactory.java | 23 +++++-
.../validator/MavenValidatorFactoryTest.java | 96 ++++++++++++++++++++++
3 files changed, 122 insertions(+), 2 deletions(-)
diff --git a/impl/maven-impl/pom.xml b/impl/maven-impl/pom.xml
index 04fb5e5e0a..4018882cb1 100644
--- a/impl/maven-impl/pom.xml
+++ b/impl/maven-impl/pom.xml
@@ -130,6 +130,11 @@ under the License.
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactory.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactory.java
index b2c68057be..0a55a1b36c 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactory.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactory.java
@@ -18,6 +18,10 @@
*/
package org.apache.maven.impl.resolver.validator;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.stream.Collectors;
+
import org.apache.maven.api.Constants;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
@@ -40,11 +44,26 @@ public enum ValidationLevel {
@Override
public Validator newInstance(RepositorySystemSession session) {
- return switch (ConfigUtils.getEnum(
- session, ValidationLevel.class, ValidationLevel.DEFAULT, Constants.MAVEN_RESOLVER_VALIDATION)) {
+ return switch (getValidationLevel(session)) {
case DEFAULT -> defaultValidator;
case MILD -> mildValidator;
case OFF -> NOOP;
};
}
+
+ private static ValidationLevel getValidationLevel(RepositorySystemSession session) {
+ String value =
+ ConfigUtils.getString(session, ValidationLevel.DEFAULT.name(), Constants.MAVEN_RESOLVER_VALIDATION);
+ try {
+ return ValidationLevel.valueOf(value.trim().toUpperCase(Locale.ROOT));
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException(
+ "Invalid value '" + value + "' for " + Constants.MAVEN_RESOLVER_VALIDATION
+ + ", supported values are: "
+ + Arrays.stream(ValidationLevel.values())
+ .map(level -> level.name().toLowerCase(Locale.ROOT))
+ .collect(Collectors.joining(", ")),
+ e);
+ }
+ }
}
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactoryTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactoryTest.java
new file mode 100644
index 0000000000..13eba1e128
--- /dev/null
+++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactoryTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.impl.resolver.validator;
+
+import java.util.Locale;
+
+import org.apache.maven.api.Constants;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.spi.validator.Validator;
+import org.eclipse.aether.spi.validator.ValidatorFactory;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests {@link MavenValidatorFactory}.
+ */
+class MavenValidatorFactoryTest {
+
+ private static final DefaultArtifact SLASH_CLASSIFIER = new DefaultArtifact("g:a:jar:lib/foo.jar:1.0");
+
+ private final MavenValidatorFactory factory = new MavenValidatorFactory();
+
+ private Validator newValidator(String level) {
+ DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false);
+ if (level != null) {
+ session.setConfigProperty(Constants.MAVEN_RESOLVER_VALIDATION, level);
+ }
+ return factory.newInstance(session);
+ }
+
+ @Test
+ void defaultWhenUnset() {
+ Validator validator = newValidator(null);
+ assertInstanceOf(MavenValidator.class, validator);
+ assertThrows(IllegalArgumentException.class, () -> validator.validateArtifact(SLASH_CLASSIFIER));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"default", "DEFAULT", "Default"})
+ void defaultLevelIgnoresCase(String level) {
+ Validator validator = newValidator(level);
+ assertInstanceOf(MavenValidator.class, validator, level);
+ assertThrows(IllegalArgumentException.class, () -> validator.validateArtifact(SLASH_CLASSIFIER), level);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"mild", "MILD", "Mild", " mild "})
+ void mildLevelIgnoresCase(String level) {
+ Validator validator = newValidator(level);
+ assertInstanceOf(MavenValidator.class, validator);
+ assertDoesNotThrow(() -> validator.validateArtifact(SLASH_CLASSIFIER));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> validator.validateArtifact(new DefaultArtifact("g:a:jar:${classifier}:1.0")));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"off", "OFF", "Off"})
+ void offLevelIgnoresCase(String level) {
+ assertSame(ValidatorFactory.NOOP, newValidator(level), level);
+ }
+
+ @Test
+ void invalidLevel() {
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> newValidator("strict"));
+ assertTrue(e.getMessage().contains(Constants.MAVEN_RESOLVER_VALIDATION), e.getMessage());
+ assertTrue(e.getMessage().contains("strict"), e.getMessage());
+ for (MavenValidatorFactory.ValidationLevel level : MavenValidatorFactory.ValidationLevel.values()) {
+ assertTrue(e.getMessage().contains(level.name().toLowerCase(Locale.ROOT)), e.getMessage());
+ }
+ }
+}