changeset 3989:93b50b70ba6c

8174715: Javadoc fails on JDK 7 and JDK 8 sources with StringIndexOutOfBoundsException Reviewed-by: jjg
author ksrini
date Wed, 15 Feb 2017 09:50:26 -0800
parents 2815405955ee
children 9b784c8acd81
files src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java test/com/sun/javadoc/testNonInlineHtmlTagRemoval/C.java test/com/sun/javadoc/testNonInlineHtmlTagRemoval/Negative.java test/com/sun/javadoc/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/C.java test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/Negative.java test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java
diffstat 7 files changed, 112 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Feb 15 11:27:03 2017 +0100
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Feb 15 09:50:26 2017 -0800
@@ -1705,7 +1705,6 @@
         if (lessThanPos < 0) {
             return text;
         }
-
         StringBuilder result = new StringBuilder();
     main: while (lessThanPos != -1) {
             int currPos = lessThanPos + 1;
@@ -1740,17 +1739,16 @@
                     if (ch == '>' && quoteKind == null) {
                         foundGT = true;
                     }
-                    if (++currPos == len)
+                    if (++currPos == len) {
                         break;
+                    }
                     ch = text.charAt(currPos);
                 }
-                startPos = currPos + 1;
-                currPos = startPos;
+                startPos = currPos;
             }
             lessThanPos = text.indexOf('<', currPos);
         }
         result.append(text.substring(startPos));
-
         return result.toString();
     }
 
@@ -1760,10 +1758,6 @@
                 ('1' <= ch && ch <= '6');
     }
 
-    private static boolean isWhitespace(char ch) {
-        return Character.isWhitespace(ch);
-    }
-
     /**
      * Add a link to the stylesheet file.
      *
--- a/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/C.java	Wed Feb 15 11:27:03 2017 +0100
+++ b/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/C.java	Wed Feb 15 09:50:26 2017 -0800
@@ -71,4 +71,9 @@
      * caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul>
      */
     public void caseA() {}
+
+    /**
+     * caseB <blockquote>A block quote example:</blockquote>
+     */
+    public void caseB() {}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/Negative.java	Wed Feb 15 09:50:26 2017 -0800
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+public class Negative {
+    /**
+     * case1: A hanging &lt;  : <blockquote>xx</blockquote><
+     */
+    public void case1() {}
+}
--- a/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java	Wed Feb 15 11:27:03 2017 +0100
+++ b/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java	Wed Feb 15 09:50:26 2017 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      8048628
+ * @bug      8048628 8174715
  * @summary  Verify html inline tags are removed correctly in the first sentence.
  * @library  ../lib
  * @modules jdk.javadoc
@@ -39,22 +39,34 @@
     }
 
     @Test
-    void test() {
-        javadoc("-d", "out",
+    void testPositive() {
+        javadoc("-d", "out1",
                 "-sourcepath", testSrc,
                 testSrc("C.java"));
         checkExit(Exit.OK);
 
         checkOutput("C.html", true,
-                "<div class=\"block\">case1 end of sentence.</div>",
-                "<div class=\"block\">case2 end of sentence.</div>",
-                "<div class=\"block\">case3 end of sentence.</div>",
-                "<div class=\"block\">case4 end of sentence.</div>",
-                "<div class=\"block\">case5 end of sentence.</div>",
-                "<div class=\"block\">case6 end of sentence.</div>",
-                "<div class=\"block\">case7 end of sentence.</div>",
-                "<div class=\"block\">case8 end of sentence.</div>",
-                "<div class=\"block\">case9 end of sentence.</div>",
-                "<div class=\"block\">caseA end of sentence.</div>");
+                "<div class=\"block\">case1   end of sentence.</div>",
+                "<div class=\"block\">case2   end of sentence.</div>",
+                "<div class=\"block\">case3   end of sentence.</div>",
+                "<div class=\"block\">case4   end of sentence.</div>",
+                "<div class=\"block\">case5   end of sentence.</div>",
+                "<div class=\"block\">case6   end of sentence.</div>",
+                "<div class=\"block\">case7   end of sentence.</div>",
+                "<div class=\"block\">case8   end of sentence.</div>",
+                "<div class=\"block\">case9   end of sentence.</div>",
+                "<div class=\"block\">caseA   end of sentence.</div>",
+                "<div class=\"block\">caseB A block quote example:</div>");
+    }
+
+    @Test
+    void testNegative() {
+        javadoc("-d", "out2",
+                "-sourcepath", testSrc,
+                testSrc("Negative.java"));
+        checkExit(Exit.FAILED);
+
+        checkOutput("Negative.html", true,
+                "<div class=\"block\">case1: A hanging &lt;  : xx<</div>");
     }
 }
--- a/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/C.java	Wed Feb 15 11:27:03 2017 +0100
+++ b/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/C.java	Wed Feb 15 09:50:26 2017 -0800
@@ -71,4 +71,9 @@
      * caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul>
      */
     public void caseA() {}
+
+    /**
+     * caseB <blockquote>A block quote example:</blockquote>
+     */
+    public void caseB() {}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/Negative.java	Wed Feb 15 09:50:26 2017 -0800
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+public class Negative {
+    /**
+     * case1: A hanging &lt;  : <blockquote>xx</blockquote><
+     */
+    public void case1() {}
+}
--- a/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java	Wed Feb 15 11:27:03 2017 +0100
+++ b/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java	Wed Feb 15 09:50:26 2017 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      8048628
+ * @bug      8048628 8174715
  * @summary  Verify html inline tags are removed correctly in the first sentence.
  * @library  ../lib
  * @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -39,8 +39,8 @@
     }
 
     @Test
-    void test() {
-        javadoc("-d", "out",
+    void testPositive() {
+        javadoc("-d", "out1",
                 "-sourcepath", testSrc,
                 testSrc("C.java"));
         checkExit(Exit.OK);
@@ -55,6 +55,18 @@
                 "<div class=\"block\">case7   end of sentence.</div>",
                 "<div class=\"block\">case8   end of sentence.</div>",
                 "<div class=\"block\">case9   end of sentence.</div>",
-                "<div class=\"block\">caseA   end of sentence.</div>");
+                "<div class=\"block\">caseA   end of sentence.</div>",
+                "<div class=\"block\">caseB A block quote example:</div>");
+    }
+
+    @Test
+    void testNegative() {
+        javadoc("-d", "out2",
+                "-sourcepath", testSrc,
+                testSrc("Negative.java"));
+        checkExit(Exit.ERROR);
+
+        checkOutput("Negative.html", true,
+                "<div class=\"block\">case1: A hanging &lt;  : xx<</div>");
     }
 }