2020
2121import java .io .File ;
2222import java .io .IOException ;
23- import java .nio .charset .CharacterCodingException ;
2423import java .nio .charset .Charset ;
24+ import java .nio .charset .StandardCharsets ;
2525import java .nio .file .DirectoryStream ;
2626import java .nio .file .Files ;
2727import java .nio .file .Path ;
3131import java .util .List ;
3232
3333import org .apache .maven .reporting .MavenReportException ;
34+ import org .codehaus .plexus .languages .java .version .JavaVersion ;
3435import 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 */
4241public 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