The method DefaultStyledDocument.getParagraphElement must always return an
element and not null. If the position argument is outside the bounds of
the document, then the closest element should be returned (according to
the specs). This is fixed.
2005-09-20 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/text/DefaultStyledDocument.java
(getParagraphElement): If the position argument is out of the
document's bounds, then the closest paragraph element must be
returned. This is fixed.
/Roman
Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.12
diff -u -r1.12 DefaultStyledDocument.java
--- javax/swing/text/DefaultStyledDocument.java 20 Sep 2005 08:57:39 -0000 1.12
+++ javax/swing/text/DefaultStyledDocument.java 20 Sep 2005 14:51:46 -0000
@@ -899,6 +899,10 @@
/**
* Returns the paragraph element for the specified position.
+ * If the position is outside the bounds of the document's root element,
+ * then the closest element is returned. That is the last paragraph if
+ * <code>position >= endIndex</code> or the first paragraph if
+ * <code>position < startIndex</code>.
*
* @param position the position for which to query the paragraph element
*
@@ -907,7 +911,16 @@
public Element getParagraphElement(int position)
{
BranchElement root = (BranchElement) getDefaultRootElement();
+ int start = root.getStartOffset();
+ int end = root.getEndOffset();
+ if (position >= end)
+ position = end - 1;
+ else if (position < start)
+ position = start;
+
Element par = root.positionToElement(position);
+
+ assert par != null : "The paragraph element must not be null";
return par;
}
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches