From 316de7df14b8b3046499b1d07365d090935e5fdc Mon Sep 17 00:00:00 2001 From: Abdullah <89297042+AzazelSensei@users.noreply.github.com> Date: Mon, 24 Aug 2026 06:19:52 +0000 Subject: [PATCH 1/3] Do not let effective-pom encoding fall back to null prettyFormat throws when the encoding name is null. Fall back to UTF-8 instead of the platform charset. --- .../maven/plugins/help/EffectivePomMojo.java | 15 +++++++- .../plugins/help/EffectivePomMojoTest.java | 38 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java index 4fa115c2..b50817af 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -107,7 +107,13 @@ public void execute() throws MojoExecutionException { } StringWriter w = new StringWriter(); - String encoding = output != null ? project.getModel().getModelEncoding() : System.getProperty("file.encoding"); + String rawEncoding; + if (output != null) { + rawEncoding = project.getModel().getModelEncoding(); + } else { + rawEncoding = System.getProperty("file.encoding"); + } + String encoding = encodingOrDefault(rawEncoding); XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null); @@ -213,6 +219,13 @@ private static void cleanModel(Model pom) { pom.setProperties(properties); } + static String encodingOrDefault(String encoding) { + if (encoding == null || encoding.isEmpty()) { + return "UTF-8"; + } + return encoding; + } + private static class InputLocationStringFormatter extends InputLocation.StringFormatter { @Override public String toString(InputLocation location) { diff --git a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java new file mode 100644 index 00000000..73de3cf3 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java @@ -0,0 +1,38 @@ +/* + * 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.plugins.help; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class EffectivePomMojoTest { + + @Test + void encodingOrDefaultFallsBackToUtf8() { + assertEquals("UTF-8", EffectivePomMojo.encodingOrDefault(null)); + assertEquals("UTF-8", EffectivePomMojo.encodingOrDefault("")); + } + + @Test + void encodingOrDefaultKeepsExplicitValue() { + assertEquals("UTF-8", EffectivePomMojo.encodingOrDefault("UTF-8")); + assertEquals("ISO-8859-1", EffectivePomMojo.encodingOrDefault("ISO-8859-1")); + } +} From 74fbaac8783d290497698f1c43f3d210368d2631 Mon Sep 17 00:00:00 2001 From: Abdullah <89297042+AzazelSensei@users.noreply.github.com> Date: Mon, 24 Aug 2026 12:06:28 +0000 Subject: [PATCH 2/3] Write effective POM as UTF-8 when no output file is set --- .../org/apache/maven/plugins/help/EffectivePomMojo.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java index b50817af..7e388795 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -107,12 +107,7 @@ public void execute() throws MojoExecutionException { } StringWriter w = new StringWriter(); - String rawEncoding; - if (output != null) { - rawEncoding = project.getModel().getModelEncoding(); - } else { - rawEncoding = System.getProperty("file.encoding"); - } + String rawEncoding = output != null ? project.getModel().getModelEncoding() : "UTF-8"; String encoding = encodingOrDefault(rawEncoding); XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null); From 0633014093e0e53a8e32b63af611174d251e7e0d Mon Sep 17 00:00:00 2001 From: Abdullah <89297042+AzazelSensei@users.noreply.github.com> Date: Thu, 27 Aug 2026 09:26:55 +0000 Subject: [PATCH 3/3] Use the model encoding for effective-pom regardless of output --- .../java/org/apache/maven/plugins/help/EffectivePomMojo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java index 7e388795..f5855620 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -107,8 +107,7 @@ public void execute() throws MojoExecutionException { } StringWriter w = new StringWriter(); - String rawEncoding = output != null ? project.getModel().getModelEncoding() : "UTF-8"; - String encoding = encodingOrDefault(rawEncoding); + String encoding = encodingOrDefault(project.getModel().getModelEncoding()); XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null);