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/08/24 06:19:20 UTC
(maven) branch maven-4.0.x updated: [backport maven-4.0.x] Make profile activation conditions locale-independent
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 ff854212a2 [backport maven-4.0.x] Make profile activation conditions locale-independent
ff854212a2 is described below
commit ff854212a22c57fbf98abe861cdc9fa2f47e5a9c
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Aug 24 08:19:15 2026 +0200
[backport maven-4.0.x] Make profile activation conditions locale-independent
Cherry-pick of #12735 onto maven-4.0.x.
Uses Locale.ROOT in profile activation condition evaluation to prevent
locale-dependent behavior: upper(), lower(), and numeric formatting now
produce consistent results regardless of the JVM's default locale.
Turkish/Azeri locales map i/I differently, and locales with non-latin
numbering systems render digits differently in String.format, causing
profile conditions to silently fail.
Also includes fix for BuildPlanExecutor thread pool leak on constructor
failure: reorders plan building before executor creation so a failure in
buildInitialPlan() cannot leak the thread pool.
Closes #12798
---
.../impl/model/profile/ConditionFunctions.java | 11 +++++-
.../maven/impl/model/profile/ConditionParser.java | 8 +++-
.../impl/model/profile/ConditionParserTest.java | 44 ++++++++++++++++++++++
3 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java
index 1a90872739..baa6482379 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java
@@ -19,6 +19,7 @@
package org.apache.maven.impl.model.profile;
import java.util.List;
+import java.util.Locale;
import org.apache.maven.api.services.InterpolatorException;
import org.apache.maven.api.services.ModelBuilderException;
@@ -65,6 +66,9 @@ public Object length(List<Object> args) {
/**
* Converts the given string to uppercase.
+ * <p>
+ * The conversion uses {@link Locale#ROOT} so that profile activation does not depend on the
+ * default locale of the machine running the build.
*
* @param args A list containing a single string argument
* @return The uppercase version of the input string
@@ -75,11 +79,14 @@ public Object upper(List<Object> args) {
throw new IllegalArgumentException("upper function requires exactly one argument");
}
String s = ConditionParser.toString(args.get(0));
- return s.toUpperCase();
+ return s.toUpperCase(Locale.ROOT);
}
/**
* Converts the given string to lowercase.
+ * <p>
+ * The conversion uses {@link Locale#ROOT} so that profile activation does not depend on the
+ * default locale of the machine running the build.
*
* @param args A list containing a single string argument
* @return The lowercase version of the input string
@@ -90,7 +97,7 @@ public Object lower(List<Object> args) {
throw new IllegalArgumentException("lower function requires exactly one argument");
}
String s = ConditionParser.toString(args.get(0));
- return s.toLowerCase();
+ return s.toLowerCase(Locale.ROOT);
}
/**
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java
index a34e6e23cd..7322959fd3 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.function.UnaryOperator;
@@ -564,6 +565,11 @@ private static Object compare(Object left, String operator, Object right) {
* Converts an object to a string representation.
* If the object is a {@code Double}, it formats it without any decimal places.
* Otherwise, it uses the {@code String.valueOf} method.
+ * <p>
+ * Formatting uses {@link Locale#ROOT} so that profile activation does not depend on the
+ * default locale of the machine running the build. Without it, a locale whose default
+ * numbering system is not latin (for example {@code hi-IN-u-nu-deva}) would render
+ * {@code 42} as {@code ४२}.
*
* @param value the object to convert to a string
* @return the string representation of the object
@@ -572,7 +578,7 @@ public static String toString(Object value) {
if (value instanceof Double || value instanceof Float) {
double doubleValue = ((Number) value).doubleValue();
if (doubleValue == Math.floor(doubleValue) && !Double.isInfinite(doubleValue)) {
- return String.format("%.0f", doubleValue);
+ return String.format(Locale.ROOT, "%.0f", doubleValue);
}
}
return String.valueOf(value);
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java
index c1eb0a5735..088928eefa 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.maven.impl.model.profile;
+import java.util.Locale;
import java.util.Map;
import java.util.function.UnaryOperator;
@@ -94,6 +95,49 @@ void testCaseConversionFunctions() {
assertEquals("world", parser.parse("lower('WORLD')"));
}
+ /**
+ * The result of {@code upper()} and {@code lower()} must not depend on the default locale of
+ * the machine running the build. In the Turkish locale the default case mapping turns
+ * {@code i} into the dotted {@code İ} and {@code I} into the dotless {@code ı}, which would
+ * silently change whether a profile is activated.
+ */
+ @Test
+ void testCaseConversionFunctionsAreLocaleIndependent() {
+ Locale orig = Locale.getDefault();
+ try {
+ Locale[] locales = {Locale.ENGLISH, new Locale("tr")};
+ for (Locale locale : locales) {
+ Locale.setDefault(locale);
+ assertEquals("WINDOWS", parser.parse("upper('windows')"), "upper() in " + locale);
+ assertEquals("LINUX", parser.parse("upper('linux')"), "upper() in " + locale);
+ assertEquals("linux", parser.parse("lower('LINUX')"), "lower() in " + locale);
+ assertEquals("ci", parser.parse("lower('CI')"), "lower() in " + locale);
+ }
+ } finally {
+ Locale.setDefault(orig);
+ }
+ }
+
+ /**
+ * Numbers must render with latin digits regardless of the default locale, otherwise a
+ * condition comparing against a string literal would evaluate differently on a machine
+ * whose locale uses a non-latin numbering system.
+ */
+ @Test
+ void testNumberFormattingIsLocaleIndependent() {
+ Locale orig = Locale.getDefault();
+ try {
+ // this locale's default numbering system is Devanagari rather than latin
+ Locale.setDefault(Locale.forLanguageTag("hi-IN-u-nu-deva"));
+ assertEquals("42", ConditionParser.toString(42.0));
+ assertEquals("42", ConditionParser.toString(42.0f));
+ assertEquals("The answer is 42", parser.parse("'The answer is ' + 42.0"));
+ assertEquals(2, parser.parse("length(42.0)"));
+ } finally {
+ Locale.setDefault(orig);
+ }
+ }
+
@Test
void testConcatFunction() {
assertEquals("HelloWorld", parser.parse("'Hello' + 'World'"));