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

swing.text.DefaultEditorKit.write(...) does not throw BadLocationException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      swing1.1
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: akC57697 Date: 03/31/98



      The java.awt.swing.text.DefaultEditorKit.write(...) does not
      throw BadLocationException but may throws java.lang.ArrayIndexOutOfBoundsException
      The doc says:
      " .........
          exception BadLocationException if pos represents an invalid
          location within the document.
         .........
      "
      -----------------------Example--------------------
      import java.awt.swing.text.*;
      import java.io.*;

      public class testDefaultKit {
          public static void main(String s[]) {
          
            String string = new String("A string");
            java.io.StringReader reader = new java.io.StringReader(string);
            DefaultEditorKit editor = new DefaultEditorKit();
            Document doc = new PlainDocument();
            PrintWriter writer = new PrintWriter(System.out);
            
            try {
             editor.read(reader,doc,0); // Insert the string
             reader.close();
       
             try {
              editor.write(writer,doc,-1,doc.getLength()); // Illegal pos
             } catch (BadLocationException ex)
                      {
                       System.out.println("OKAY");
                       return;
                      }
         
            } catch (Exception e) {
                     System.out.println("Unexpected : "+e);
                     return;
                    }
                    
                System.out.println("No exceptions");
        }
      }
      --------------------------------------------------
      Output:
      Unexpected : java.lang.ArrayIndexOutOfBoundsException

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

        Attachments

          Activity

            People

            Assignee:
            tprinzinsunw Timothy Prinzing (Inactive)
            Reporter:
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: