Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4133059

HTMLEditorKit.read(...) fails to throw BadLocationException when it should

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      sparc
    • OS:
      solaris_2.5.1
    • Verification:
      Verified

      Description



      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)


      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            smanisunw Sunita Mani (Inactive)
            Reporter:
            aalievsunw Artem Aliev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: