harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey A. Ivanov (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-2777) [classlib][swing] j.s.text.AbstractDocument.BranchElement.get{Start, End}Offset throw ArrayIndexOutOfBoundsException rather than NPE
Date Mon, 18 Dec 2006 13:41:21 GMT
[classlib][swing] j.s.text.AbstractDocument.BranchElement.get{Start, End}Offset throw ArrayIndexOutOfBoundsException
rather than NPE
------------------------------------------------------------------------------------------------------------------------------------

                 Key: HARMONY-2777
                 URL: http://issues.apache.org/jira/browse/HARMONY-2777
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Alexey A. Ivanov
            Priority: Minor


The spec states that getEndOffset throws NPE if the element has no children [1].
The spec doesn't say anything about exceptions for getStartOffset() [2]. However, it also
throws NPE in this case. The behavior of these methods should be similar in respect to exceptions.

[1] http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/AbstractDocument.BranchElement.html#getEndOffset()
[2] http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/AbstractDocument.BranchElement.html#getStartOffset()


======= Code to Reproduce =======
import javax.swing.text.PlainDocument;
import javax.swing.text.AbstractDocument.BranchElement;

public class Test {
    public static void main(String[] args) {
        PlainDocument doc = new PlainDocument();
        BranchElement branch = doc.new BranchElement(null, null);
        try {
            System.err.println(branch.getStartOffset());
        } catch (Exception e) {
            System.err.println("getStartOffset:");
            e.printStackTrace();
        }
        try {
            System.err.println(branch.getEndOffset());
        } catch (Exception e) {
            System.err.println("getEndOffset:");
            e.printStackTrace();
        }
    }
}
======= end of code =======


------- Harmony Output -------
getStartOffset:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
	at javax.swing.text.AbstractDocument$BranchElement.getStartOffset(AbstractDocument.java:419)
	at Test.main(Test.java:9)
getEndOffset:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -1
	at javax.swing.text.AbstractDocument$BranchElement.getEndOffset(AbstractDocument.java:48)
	at Test.main(Test.java:15)
------- end of Harmony -------

------- RI Output -------
getStartOffset:
java.lang.NullPointerException
	at javax.swing.text.AbstractDocument$BranchElement.getStartOffset(AbstractDocument.java:2331)
	at Test.main(Test.java:9)
getEndOffset:
java.lang.NullPointerException
	at javax.swing.text.AbstractDocument$BranchElement.getEndOffset(AbstractDocument.java:2343)
	at Test.main(Test.java:15)
------- end of RI -------

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message