-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2fcs
-
sparc
-
solaris_2.5.1
-
Verified
Name: aaC67449 Date: 04/28/98
HTMLEditorKit.read(...) throws IOException, when it must throw BadLocationException ("pos represents an invalid location within the document").
Javadoc says:"
public void read(Reader in,
Document doc,
int pos) throws IOException, BadLocationException
Create and initialize a model from the given stream which is expected to be in a format
appropriate for this kind of editor. This is implemented to read html 3.2 text.
Parameters:
in - The stream to read from
doc - The destination for the insertion.
pos - The location in the document to place the content.
Throws:
IOException - on any I/O error
BadLocationException - if pos represents an invalid location within the document.
Overrides:
read in class DefaultEditorKit"
------------------Example-----------------------------------
import java.awt.swing.text.html.*;
import java.awt.swing.text.*;
import java.io.*;
public class Test {
public static void main(String argv[]) {
String test="<!DOCTYPE HTML PUBLIC \"-//w3c//DTD html 3.2//EN\"><HTML><HEAD><TITLE>test</TITLE></HEAD><BODY><P> Test 1 Test 2 Test 3 </P></BODY></HTML>";
HTMLEditorKit c = new HTMLEditorKit();
try {
Document doc=c.createDefaultDocument();
c.read(new StringReader(test),doc,3); // must throw BadLocationException
System.out.println("Failed");
} catch(BadLocationException e) {
System.out.println("Passed");
} catch(Exception e) {
System.out.println("Failed");
e.printStackTrace();
}
}
}
-------------------Output------------------------------------
Failed
java.io.IOException: BadLocationException: Invalid location
at java.awt.swing.text.html.HTMLDocument$HTMLReader.read(HTMLDocument.java:240)
at java.awt.swing.text.html.HTMLDocument.read(HTMLDocument.java:140)
at java.awt.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:112)
at Test.main(Test.java:12)
======================================================================