Skip to content

Commit 0af2fde

Browse files
committed
Revert "Fix MalformedInputException on Windows with Java 8 due to charset mis… (#1274)"
This reverts commit b453602.
1 parent b453602 commit 0af2fde

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

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

2121
import java.io.File;
2222
import java.io.IOException;
23-
import java.nio.charset.CharacterCodingException;
2423
import java.nio.charset.Charset;
24+
import java.nio.charset.StandardCharsets;
2525
import java.nio.file.DirectoryStream;
2626
import java.nio.file.Files;
2727
import java.nio.file.Path;
@@ -31,15 +31,29 @@
3131
import java.util.List;
3232

3333
import org.apache.maven.reporting.MavenReportException;
34+
import org.codehaus.plexus.languages.java.version.JavaVersion;
3435
import org.codehaus.plexus.util.cli.Commandline;
3536

36-
import static java.nio.charset.StandardCharsets.UTF_8;
37-
3837
/**
3938
* Helper class to compute and write data used to detect a
4039
* stale javadoc.
4140
*/
4241
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+
4357
/**
4458
* Compute the data used to detect a stale javadoc
4559
*
@@ -58,12 +72,8 @@ public static List<String> getStaleData(Commandline cmd) throws MavenReportExcep
5872
for (String arg : args) {
5973
if (arg.startsWith("@")) {
6074
String name = arg.substring(1);
75+
options.addAll(Files.readAllLines(dir.resolve(name), getDataCharset()));
6176
ignored.add(name);
62-
try {
63-
options.addAll(Files.readAllLines(dir.resolve(name), UTF_8));
64-
} catch (CharacterCodingException e) {
65-
options.addAll(Files.readAllLines(dir.resolve(name), Charset.defaultCharset()));
66-
}
6777
}
6878
}
6979
List<String> state = new ArrayList<>(options);
@@ -113,7 +123,7 @@ public static void writeStaleData(Commandline cmd, Path path) throws MavenReport
113123
try {
114124
List<String> curdata = getStaleData(cmd);
115125
Files.createDirectories(path.getParent());
116-
Files.write(path, curdata, UTF_8);
126+
Files.write(path, curdata, getDataCharset());
117127
} catch (IOException e) {
118128
throw new MavenReportException("Error checking stale data", e);
119129
}

0 commit comments

Comments
 (0)