Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8188649

javadoc -encoding doesn't work when using the old doclet API

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 10
    • Component/s: tools
    • Labels:

      Backports

        Description

        In JDK 9, the javadoc flag -encoding fails to override the default encoding when using the old doclet API.

        The following patch fixes the bug:

        ```
        diff --git a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java
        --- a/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java
        +++ b/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java
        @@ -157,10 +157,11 @@
             ENCODING("-encoding", true) {
                 @Override
                 public void process(Helper helper, String arg) {
                     helper.encoding = arg;
                     helper.setCompilerOpt(opt, arg);
        + helper.setFileManagerOpt(Option.ENCODING, arg);
                 }
             },
         
             RELEASE("--release", true) {
                 @Override
        ```

        Repro:

        === Doclet.java
        import com.sun.javadoc.*;
        public class Doclet extends com.sun.javadoc.Doclet {
          public static LanguageVersion languageVersion() {
            return LanguageVersion.JAVA_1_5;
          }
        }
        === Test.java
        /** 🥑 */
        class Test {}
        ===

        $ javac -cp $JAVA_HOME/lib/tools.jar Doclet.java

        with 1.8.0_152-ea:

        $ javadoc -J-Dfile.encoding=ascii -doclet Doclet -docletpath . -encoding UTF-8 Test.java
        ... OK

        with 9+181:

        $ javadoc -J-Dfile.encoding=ascii -doclet Doclet -docletpath . -encoding UTF-8 Test.java
        javadoc: warning - The old Doclet and Taglet APIs in the packages
        com.sun.javadoc, com.sun.tools.doclets and their implementations
        are planned to be removed in a future JDK release. These
        components have been superseded by the new APIs in jdk.javadoc.doclet.
        Users are strongly recommended to migrate to the new APIs.
        Loading source file Test.java...
        Test.java:1: error: unmappable character (0xF0) for encoding US-ASCII
        /** ???? */
            ^

          Activity

          cushon Liam Miller-Cushon created issue -
          jjg Jonathan Gibbons made changes -
          Field Original Value New Value
          Status New [ 10000 ] Open [ 1 ]
          jjg Jonathan Gibbons made changes -
          Assignee Jonathan Gibbons [ jjg ]
          jjg Jonathan Gibbons made changes -
          Fix Version/s 10 [ 16302 ]
          jjg Jonathan Gibbons made changes -
          Labels trivial
          Hide
          jjg Jonathan Gibbons added a comment -
          While this is easy to fix, note the old doclet API is getting older and will go away at some point
          Show
          jjg Jonathan Gibbons added a comment - While this is easy to fix, note the old doclet API is getting older and will go away at some point
          Hide
          jjg Jonathan Gibbons added a comment -
          What is the exact character sequence for that Test.java file ... the one with the guacamole?
          Show
          jjg Jonathan Gibbons added a comment - What is the exact character sequence for that Test.java file ... the one with the guacamole?
          Hide
          cushon Liam Miller-Cushon added a comment -
          I used U+1F951. This program will generate a Test.java that reproduces the bug:

          ```
          import java.nio.charset.StandardCharsets;
          import java.nio.file.Files;
          import java.nio.file.Paths;
          class Gen {
            public static void main(String[] args) throws Exception {
              Files.write(Paths.get("Test.java"), "/** \uD83E\uDD51 */ class T {}".getBytes(StandardCharsets.UTF_8));
            }
          }
          ```
          Show
          cushon Liam Miller-Cushon added a comment - I used U+1F951. This program will generate a Test.java that reproduces the bug: ``` import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; class Gen {   public static void main(String[] args) throws Exception {     Files.write(Paths.get("Test.java"), "/** \uD83E\uDD51 */ class T {}".getBytes(StandardCharsets.UTF_8));   } } ```
          Hide
          jjg Jonathan Gibbons added a comment -
          Thanks. This is going to be one of those fixes where all the work is in writing the test case ;-)
          Show
          jjg Jonathan Gibbons added a comment - Thanks. This is going to be one of those fixes where all the work is in writing the test case ;-)
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk/jdk10/rev/cb7926b6b3d6
          User: jjg
          Date: 2018-01-05 20:46:01 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk/jdk10/rev/cb7926b6b3d6 User: jjg Date: 2018-01-05 20:46:01 +0000
          hgupdate HG Updates made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolved In Build master [ 18256 ]
          Resolution Fixed [ 1 ]
          hgupdate HG Updates made changes -
          Link This issue backported by JDK-8194700 [ JDK-8194700 ]
          hgupdate HG Updates made changes -
          Link This issue backported by JDK-8194798 [ JDK-8194798 ]
          hgupdate HG Updates made changes -
          Resolved In Build master [ 18256 ] b39 [ 17426 ]

            People

            • Assignee:
              jjg Jonathan Gibbons
              Reporter:
              cushon Liam Miller-Cushon
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: