This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new b453602a Fix MalformedInputException on Windows with Java 8 due to
charset mis… (#1274)
b453602a is described below
commit b453602ab37ab339b887d39b2efc8ebdd35f8dab
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Thu Oct 16 00:38:00 2025 +0200
Fix MalformedInputException on Windows with Java 8 due to charset mis…
(#1274)
* 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 | 28 +++++++---------------
1 file changed, 9 insertions(+), 19 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..4cf8187c 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,8 @@ package org.apache.maven.plugins.javadoc;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.CharacterCodingException;
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 +31,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,8 +58,12 @@ public class StaleHelper {
for (String arg : args) {
if (arg.startsWith("@")) {
String name = arg.substring(1);
- options.addAll(Files.readAllLines(dir.resolve(name),
getDataCharset()));
ignored.add(name);
+ try {
+ options.addAll(Files.readAllLines(dir.resolve(name),
UTF_8));
+ } catch (CharacterCodingException e) {
+ options.addAll(Files.readAllLines(dir.resolve(name),
Charset.defaultCharset()));
+ }
}
}
List<String> state = new ArrayList<>(options);
@@ -123,7 +113,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);
}