Fri, 04 Mar 2011 19:56:02 -0800
6227454: package.html and overview.html may not be read fully
Reviewed-by: bpatel
1.1 --- a/src/share/classes/com/sun/tools/javadoc/DocImpl.java Fri Mar 04 19:53:03 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocImpl.java Fri Mar 04 19:56:02 2011 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,6 +25,7 @@ 1.11 1.12 package com.sun.tools.javadoc; 1.13 1.14 +import java.io.DataInputStream; 1.15 import java.io.InputStream; 1.16 import java.io.IOException; 1.17 import java.text.CollationKey; 1.18 @@ -33,6 +34,8 @@ 1.19 import com.sun.javadoc.*; 1.20 1.21 import com.sun.tools.javac.util.Position; 1.22 +import java.util.regex.Matcher; 1.23 +import java.util.regex.Pattern; 1.24 1.25 /** 1.26 * abstract base class of all Doc classes. Doc item's are representations 1.27 @@ -166,51 +169,28 @@ 1.28 * Utility for subclasses which read HTML documentation files. 1.29 */ 1.30 String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { 1.31 - int filesize = input.available(); 1.32 - byte[] filecontents = new byte[filesize]; 1.33 - input.read(filecontents, 0, filesize); 1.34 - input.close(); 1.35 + byte[] filecontents = new byte[input.available()]; 1.36 + try { 1.37 + DataInputStream dataIn = new DataInputStream(input); 1.38 + dataIn.readFully(filecontents); 1.39 + } finally { 1.40 + input.close(); 1.41 + } 1.42 String encoding = env.getEncoding(); 1.43 String rawDoc = (encoding!=null) 1.44 ? new String(filecontents, encoding) 1.45 : new String(filecontents); 1.46 - String upper = null; 1.47 - int bodyIdx = rawDoc.indexOf("<body"); 1.48 - if (bodyIdx == -1) { 1.49 - bodyIdx = rawDoc.indexOf("<BODY"); 1.50 - if (bodyIdx == -1) { 1.51 - upper = rawDoc.toUpperCase(); 1.52 - bodyIdx = upper.indexOf("<BODY"); 1.53 - if (bodyIdx == -1) { 1.54 - env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), 1.55 - "javadoc.Body_missing_from_html_file"); 1.56 - return ""; 1.57 - } 1.58 - } 1.59 - } 1.60 - bodyIdx = rawDoc.indexOf('>', bodyIdx); 1.61 - if (bodyIdx == -1) { 1.62 - env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), 1.63 - "javadoc.Body_missing_from_html_file"); 1.64 + Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); 1.65 + Matcher m = bodyPat.matcher(rawDoc); 1.66 + if (m.matches()) { 1.67 + return m.group(1); 1.68 + } else { 1.69 + String key = rawDoc.matches("(?is).*<body\\b.*") 1.70 + ? "javadoc.End_body_missing_from_html_file" 1.71 + : "javadoc.Body_missing_from_html_file"; 1.72 + env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); 1.73 return ""; 1.74 } 1.75 - ++bodyIdx; 1.76 - int endIdx = rawDoc.indexOf("</body", bodyIdx); 1.77 - if (endIdx == -1) { 1.78 - endIdx = rawDoc.indexOf("</BODY", bodyIdx); 1.79 - if (endIdx == -1) { 1.80 - if (upper == null) { 1.81 - upper = rawDoc.toUpperCase(); 1.82 - } 1.83 - endIdx = upper.indexOf("</BODY", bodyIdx); 1.84 - if (endIdx == -1) { 1.85 - env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), 1.86 - "javadoc.End_body_missing_from_html_file"); 1.87 - return ""; 1.88 - } 1.89 - } 1.90 - } 1.91 - return rawDoc.substring(bodyIdx, endIdx); 1.92 } 1.93 1.94 /** 1.95 @@ -256,6 +236,7 @@ 1.96 /** 1.97 * Returns a string representation of this Doc item. 1.98 */ 1.99 + @Override 1.100 public String toString() { 1.101 return qualifiedName(); 1.102 }
2.1 --- a/src/share/classes/com/sun/tools/javadoc/resources/javadoc.properties Fri Mar 04 19:53:03 2011 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javadoc/resources/javadoc.properties Fri Mar 04 19:56:02 2011 -0800 2.3 @@ -1,5 +1,5 @@ 2.4 # 2.5 -# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2.6 +# Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 # 2.9 # This code is free software; you can redistribute it and/or modify it 2.10 @@ -104,7 +104,7 @@ 2.11 tag.End_delimiter_missing_for_possible_SeeTag=End Delimiter } missing for possible See Tag in comment string: "{0}" 2.12 tag.Improper_Use_Of_Link_Tag=Missing closing ''}'' character for inline tag: "{0}" 2.13 javadoc.File_Read_Error=Error while reading file {0} 2.14 -javadoc.Body_missing_from_html_file=Body tag missing from HTML 2.15 +javadoc.Body_missing_from_html_file=Body tag missing from HTML file 2.16 javadoc.End_body_missing_from_html_file=Close body tag missing from HTML file 2.17 javadoc.Multiple_package_comments=Multiple sources of package comments found for package "{0}" 2.18 javadoc.class_not_found=Class {0} not found.
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javadoc/6227454/Test.java Fri Mar 04 19:56:02 2011 -0800 3.3 @@ -0,0 +1,141 @@ 3.4 +/* 3.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 6227454 3.30 + * @summary package.html and overview.html may not be read fully 3.31 + */ 3.32 + 3.33 +import java.io.*; 3.34 + 3.35 +import com.sun.javadoc.Doclet; 3.36 +import com.sun.javadoc.RootDoc; 3.37 + 3.38 +public class Test extends Doclet { 3.39 + public static void main(String... args) throws Exception { 3.40 + new Test().run(); 3.41 + } 3.42 + 3.43 + void run() throws Exception { 3.44 + test("<html><body>ABC XYZ</body></html>"); 3.45 + test("<html><body>ABC XYZ</BODY></html>"); 3.46 + test("<html><BODY>ABC XYZ</body></html>"); 3.47 + test("<html><BODY>ABC XYZ</BODY></html>"); 3.48 + test("<html><BoDy>ABC XYZ</bOdY></html>"); 3.49 + test("<html> ABC XYZ</bOdY></html>", "Body tag missing from HTML"); 3.50 + test("<html><body>ABC XYZ </html>", "Close body tag missing from HTML"); 3.51 + test("<html> ABC XYZ </html>", "Body tag missing from HTML"); 3.52 + test("<html><body>ABC" + bigText(8192, 40) + "XYZ</body></html>"); 3.53 + 3.54 + if (errors > 0) 3.55 + throw new Exception(errors + " errors occurred"); 3.56 + } 3.57 + 3.58 + void test(String text) throws IOException { 3.59 + test(text, null); 3.60 + } 3.61 + 3.62 + void test(String text, String expectError) throws IOException { 3.63 + testNum++; 3.64 + System.err.println("test " + testNum); 3.65 + File file = writeFile("overview" + testNum + ".html", text); 3.66 + String thisClassName = Test.class.getName(); 3.67 + File testSrc = new File(System.getProperty("test.src")); 3.68 + String[] args = { 3.69 + "-bootclasspath", 3.70 + System.getProperty("java.class.path") 3.71 + + File.pathSeparator 3.72 + + System.getProperty("sun.boot.class.path"), 3.73 + "-classpath", ".", 3.74 + "-package", 3.75 + "-overview", file.getPath(), 3.76 + new File(testSrc, thisClassName + ".java").getPath() 3.77 + }; 3.78 + 3.79 + StringWriter sw = new StringWriter(); 3.80 + PrintWriter pw = new PrintWriter(sw); 3.81 + int rc = com.sun.tools.javadoc.Main.execute( 3.82 + "javadoc", 3.83 + pw, pw, pw, 3.84 + thisClassName, 3.85 + args); 3.86 + pw.close(); 3.87 + String out = sw.toString(); 3.88 + if (!out.isEmpty()) 3.89 + System.err.println(out); 3.90 + System.err.println("javadoc exit: rc=" + rc); 3.91 + 3.92 + if (expectError == null) { 3.93 + if (rc != 0) 3.94 + error("unexpected exit from javadoc; rc:" + rc); 3.95 + } else { 3.96 + if (!out.contains(expectError)) 3.97 + error("expected error text not found: " + expectError); 3.98 + } 3.99 + } 3.100 + 3.101 + String bigText(int lines, int lineLength) { 3.102 + StringBuilder sb = new StringBuilder(); 3.103 + for (int i = 0; i < lineLength; i++) 3.104 + sb.append(String.valueOf(i % 10)); 3.105 + sb.append("\n"); 3.106 + String line = sb.toString(); 3.107 + sb.setLength(0); 3.108 + for (int i = 0; i < lines; i++) 3.109 + sb.append(line); 3.110 + return sb.toString(); 3.111 + } 3.112 + 3.113 + File writeFile(String path, String body) throws IOException { 3.114 + File f = new File(path); 3.115 + FileWriter out = new FileWriter(f); 3.116 + try { 3.117 + out.write(body); 3.118 + } finally { 3.119 + out.close(); 3.120 + } 3.121 + return f; 3.122 + } 3.123 + 3.124 + void error(String msg) { 3.125 + System.err.println("Error: " + msg); 3.126 + errors++; 3.127 + } 3.128 + 3.129 + int testNum; 3.130 + int errors; 3.131 + 3.132 + public static boolean start(RootDoc root) { 3.133 + String text = root.commentText(); 3.134 + if (text.length() < 64) 3.135 + System.err.println("text: '" + text + "'"); 3.136 + else 3.137 + System.err.println("text: '" 3.138 + + text.substring(0, 20) 3.139 + + "..." 3.140 + + text.substring(text.length() - 20) 3.141 + + "'"); 3.142 + return text.startsWith("ABC") && text.endsWith("XYZ"); 3.143 + } 3.144 +}