You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2025/10/10 19:30:08 UTC
(maven-javadoc-plugin) 01/01: Fix MalformedInputException on Windows with Java 8 due to charset mismatch in stale data cache
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch windowscharset
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit 36f048ad6121d5d7b162f0e0d53519391d4254a9
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Oct 10 21:29:51 2025 +0200
Fix MalformedInputException on Windows with Java 8 due to charset mismatch in stale data cache
Changed StaleHelper to always save in UTF-8 instead of
platform-dependent default charset. This ensures consistency with
AbstractJavadocMojo.isUpToDate() which reads the stale data file using UTF-8.
Previously on Windows with Java 8:
- First run: file written with Cp1252 (default charset)
- Second run: file read with UTF-8, causing MalformedInputException
---
.../apache/maven/plugins/javadoc/StaleHelper.java | 24 ++++------------------
1 file changed, 4 insertions(+), 20 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java b/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
index 6658a7e2..ae5ef2b2 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
@@ -20,8 +20,6 @@ package org.apache.maven.plugins.javadoc;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -31,29 +29,15 @@ import java.util.Collections;
import java.util.List;
import org.apache.maven.reporting.MavenReportException;
-import org.codehaus.plexus.languages.java.version.JavaVersion;
import org.codehaus.plexus.util.cli.Commandline;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
/**
* Helper class to compute and write data used to detect a
* stale javadoc.
*/
public class StaleHelper {
-
- /**
- * Compute the encoding of the stale javadoc
- *
- * @return the encoding of the stale data
- */
- private static Charset getDataCharset() {
- if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
- && JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
- return StandardCharsets.UTF_8;
- } else {
- return Charset.defaultCharset();
- }
- }
-
/**
* Compute the data used to detect a stale javadoc
*
@@ -72,7 +56,7 @@ public class StaleHelper {
for (String arg : args) {
if (arg.startsWith("@")) {
String name = arg.substring(1);
- options.addAll(Files.readAllLines(dir.resolve(name), getDataCharset()));
+ options.addAll(Files.readAllLines(dir.resolve(name), UTF_8));
ignored.add(name);
}
}
@@ -123,7 +107,7 @@ public class StaleHelper {
try {
List<String> curdata = getStaleData(cmd);
Files.createDirectories(path.getParent());
- Files.write(path, curdata, getDataCharset());
+ Files.write(path, curdata, UTF_8);
} catch (IOException e) {
throw new MavenReportException("Error checking stale data", e);
}