-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
beta
-
sparc
-
solaris_2.5.1
Name: akC57697 Date: 04/22/99
The method
AbstractDocument.public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
does not throw BadLocationException when the given insert position is not a valid. It throws
ArrayIndexOutOfBoundsException instead.
--------------------------------8-<---------------------------------
insertString
public void insertString(int offs,
String str,
AttributeSet a)
throws BadLocationException
Inserts some content into the document. Inserting content
causes a write lock to be held while the actual changes are
taking place, followed by notification to the observers on
the thread that grabbed the write lock.
This method is thread safe, although most Swing methods are
not. Please see Threads and Swing for more information.
Specified by:
insertString in interface Document
Parameters:
offs - the starting offset >= 0
str - the string to insert; does nothing with
null/empty strings
a - the attributes for the inserted content
Throws:
BadLocationException - the given insert position is not <--!!!
a valid position within the document <--!!!
--------------------------------8-<---------------------------------
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.BadLocationException;
public class Test {
public static void main(String[] argv) {
DefaultStyledDocument doc = new DefaultStyledDocument();
String text = "The test text.";
SimpleAttributeSet attr = new SimpleAttributeSet();
try {
doc.insertString(Integer.MIN_VALUE, text, attr);
System.out.println("No exceptions");
} catch (BadLocationException e) {
System.out.println("OKAY");
}
}
}
--------------------------------8-<---------------------------------
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at javax.swing.text.GapVector.shiftGap(GapVector.java:267)
at javax.swing.text.GapContent.shiftGap(GapContent.java:356)
at javax.swing.text.GapVector.open(GapVector.java:207)
at javax.swing.text.GapVector.replace(GapVector.java:151)
at javax.swing.text.GapContent.insertString(GapContent.java:138)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:466)
at Test.main(Test.java:12)
java full version "JDK-1.3-A"
======================================================================