8174715: Javadoc fails on JDK 7 and JDK 8 sources with StringIndexOutOfBoundsException

Reviewed-by: jjg
This commit is contained in:
Kumar Srinivasan 2017-02-15 09:50:26 -08:00
parent 8a2de9b69b
commit 388550d1a4
7 changed files with 112 additions and 26 deletions

View File

@ -1705,7 +1705,6 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (lessThanPos < 0) { if (lessThanPos < 0) {
return text; return text;
} }
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
main: while (lessThanPos != -1) { main: while (lessThanPos != -1) {
int currPos = lessThanPos + 1; int currPos = lessThanPos + 1;
@ -1740,17 +1739,16 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (ch == '>' && quoteKind == null) { if (ch == '>' && quoteKind == null) {
foundGT = true; foundGT = true;
} }
if (++currPos == len) if (++currPos == len) {
break; break;
}
ch = text.charAt(currPos); ch = text.charAt(currPos);
} }
startPos = currPos + 1; startPos = currPos;
currPos = startPos;
} }
lessThanPos = text.indexOf('<', currPos); lessThanPos = text.indexOf('<', currPos);
} }
result.append(text.substring(startPos)); result.append(text.substring(startPos));
return result.toString(); return result.toString();
} }
@ -1760,10 +1758,6 @@ public class HtmlDocletWriter extends HtmlDocWriter {
('1' <= ch && ch <= '6'); ('1' <= ch && ch <= '6');
} }
private static boolean isWhitespace(char ch) {
return Character.isWhitespace(ch);
}
/** /**
* Add a link to the stylesheet file. * Add a link to the stylesheet file.
* *

View File

@ -71,4 +71,9 @@ public class C {
* caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul> * caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul>
*/ */
public void caseA() {} public void caseA() {}
/**
* caseB <blockquote>A block quote example:</blockquote>
*/
public void caseB() {}
} }

View File

@ -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() {}
}

View File

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8048628 * @bug 8048628 8174715
* @summary Verify html inline tags are removed correctly in the first sentence. * @summary Verify html inline tags are removed correctly in the first sentence.
* @library ../lib * @library ../lib
* @modules jdk.javadoc * @modules jdk.javadoc
@ -39,8 +39,8 @@ public class TestNonInlineHtmlTagRemoval extends JavadocTester {
} }
@Test @Test
void test() { void testPositive() {
javadoc("-d", "out", javadoc("-d", "out1",
"-sourcepath", testSrc, "-sourcepath", testSrc,
testSrc("C.java")); testSrc("C.java"));
checkExit(Exit.OK); checkExit(Exit.OK);
@ -55,6 +55,18 @@ public class TestNonInlineHtmlTagRemoval extends JavadocTester {
"<div class=\"block\">case7 end of sentence.</div>", "<div class=\"block\">case7 end of sentence.</div>",
"<div class=\"block\">case8 end of sentence.</div>", "<div class=\"block\">case8 end of sentence.</div>",
"<div class=\"block\">case9 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.FAILED);
checkOutput("Negative.html", true,
"<div class=\"block\">case1: A hanging &lt; : xx<</div>");
} }
} }

View File

@ -71,4 +71,9 @@ public class C {
* caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul> * caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul>
*/ */
public void caseA() {} public void caseA() {}
/**
* caseB <blockquote>A block quote example:</blockquote>
*/
public void caseB() {}
} }

View File

@ -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() {}
}

View File

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8048628 * @bug 8048628 8174715
* @summary Verify html inline tags are removed correctly in the first sentence. * @summary Verify html inline tags are removed correctly in the first sentence.
* @library ../lib * @library ../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool * @modules jdk.javadoc/jdk.javadoc.internal.tool
@ -39,8 +39,8 @@ public class TestNonInlineHtmlTagRemoval extends JavadocTester {
} }
@Test @Test
void test() { void testPositive() {
javadoc("-d", "out", javadoc("-d", "out1",
"-sourcepath", testSrc, "-sourcepath", testSrc,
testSrc("C.java")); testSrc("C.java"));
checkExit(Exit.OK); checkExit(Exit.OK);
@ -55,6 +55,18 @@ public class TestNonInlineHtmlTagRemoval extends JavadocTester {
"<div class=\"block\">case7 end of sentence.</div>", "<div class=\"block\">case7 end of sentence.</div>",
"<div class=\"block\">case8 end of sentence.</div>", "<div class=\"block\">case8 end of sentence.</div>",
"<div class=\"block\">case9 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>");
} }
} }