Skip to content

Commit 36f048a

Browse files
committed
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
1 parent 20c6e04 commit 36f048a

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23-
import java.nio.charset.Charset;
24-
import java.nio.charset.StandardCharsets;
2523
import java.nio.file.DirectoryStream;
2624
import java.nio.file.Files;
2725
import java.nio.file.Path;
@@ -31,29 +29,15 @@
3129
import java.util.List;
3230

3331
import org.apache.maven.reporting.MavenReportException;
34-
import org.codehaus.plexus.languages.java.version.JavaVersion;
3532
import org.codehaus.plexus.util.cli.Commandline;
3633

34+
import static java.nio.charset.StandardCharsets.UTF_8;
35+
3736
/**
3837
* Helper class to compute and write data used to detect a
3938
* stale javadoc.
4039
*/
4140
public class StaleHelper {
42-
43-
/**
44-
* Compute the encoding of the stale javadoc
45-
*
46-
* @return the encoding of the stale data
47-
*/
48-
private static Charset getDataCharset() {
49-
if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
50-
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
51-
return StandardCharsets.UTF_8;
52-
} else {
53-
return Charset.defaultCharset();
54-
}
55-
}
56-
5741
/**
5842
* Compute the data used to detect a stale javadoc
5943
*
@@ -72,7 +56,7 @@ public static List<String> getStaleData(Commandline cmd) throws MavenReportExcep
7256
for (String arg : args) {
7357
if (arg.startsWith("@")) {
7458
String name = arg.substring(1);
75-
options.addAll(Files.readAllLines(dir.resolve(name), getDataCharset()));
59+
options.addAll(Files.readAllLines(dir.resolve(name), UTF_8));
7660
ignored.add(name);
7761
}
7862
}
@@ -123,7 +107,7 @@ public static void writeStaleData(Commandline cmd, Path path) throws MavenReport
123107
try {
124108
List<String> curdata = getStaleData(cmd);
125109
Files.createDirectories(path.getParent());
126-
Files.write(path, curdata, getDataCharset());
110+
Files.write(path, curdata, UTF_8);
127111
} catch (IOException e) {
128112
throw new MavenReportException("Error checking stale data", e);
129113
}

0 commit comments

Comments
 (0)