8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc)
authorjjg
Tue, 02 Jan 2018 16:07:47 -0800
changeset 48423 35cf3c947420
parent 48422 cafc0ddb8db3
child 48424 8749f0b3d227
8183964: Bad lexing of javadoc comments (change in parsing/rendering of backslashes in javadoc) Reviewed-by: vromero, cushon
src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java
test/langtools/tools/javac/parser/T4910483.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java	Tue Jan 02 09:56:53 2018 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java	Tue Jan 02 16:07:47 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -394,6 +394,7 @@
                                  comment_reader.putChar('\\', false);
                              }
                              comment_reader.scanCommentChar();
+                             break;
                          case ' ':
                          case '\t':
                              comment_reader.putChar(comment_reader.ch, false);
--- a/test/langtools/tools/javac/parser/T4910483.java	Tue Jan 02 09:56:53 2018 -0800
+++ b/test/langtools/tools/javac/parser/T4910483.java	Tue Jan 02 16:07:47 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug     4910483
+ * @bug     4910483 8183961
  * @summary Javadoc renders the string ".*\\.pdf" as ".\*\.pdf"
  * @modules jdk.compiler/com.sun.tools.javac.file
  *          jdk.compiler/com.sun.tools.javac.main
@@ -41,7 +41,12 @@
 
 import javax.tools.JavaFileObject;
 
-/**Test comment abc*\\def*/
+// Test the original issue ("\\") as well as other appearances of '\',
+// including a vanilla Unicode escape (U+0021, '!'), and a sequence
+// which is not a Unicode escape
+
+/**Test comment abc*\\def\
+ *xyz\u0021\\u0021*/
 public class T4910483 {
     public static void main(String... args) {
         JavaCompiler compiler = JavaCompiler.instance(new Context());
@@ -55,7 +60,7 @@
         JCTree classDef = cu.getTypeDecls().head;
         String commentText = cu.docComments.getCommentText(classDef);
 
-        String expected = "Test comment abc*\\\\def"; // 4 '\' escapes to 2 in a string literal
+        String expected = "Test comment abc*\\\\def\\\nxyz!\\\\u0021"; // 4 '\' escapes to 2 in a string literal
         if (!expected.equals(commentText)) {
             throw new AssertionError("Incorrect comment text: [" + commentText + "], expected [" + expected + "]");
         }