Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 58231 invoked from network); 18 Dec 2006 13:57:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Dec 2006 13:57:45 -0000 Received: (qmail 53085 invoked by uid 500); 18 Dec 2006 13:57:52 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 53053 invoked by uid 500); 18 Dec 2006 13:57:52 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 53043 invoked by uid 99); 18 Dec 2006 13:57:52 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Dec 2006 05:57:52 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Dec 2006 05:57:44 -0800 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 55982714289 for ; Mon, 18 Dec 2006 05:57:24 -0800 (PST) Message-ID: <32503346.1166450244348.JavaMail.jira@brutus> Date: Mon, 18 Dec 2006 05:57:24 -0800 (PST) From: "Alexey A. Ivanov (JIRA)" To: commits@harmony.apache.org Subject: [jira] Updated: (HARMONY-2777) [classlib][swing] j.s.text.AbstractDocument.BranchElement.get{Start, End}Offset throw ArrayIndexOutOfBoundsException rather than NPE In-Reply-To: <11033655.1166449281130.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ http://issues.apache.org/jira/browse/HARMONY-2777?page=all ] Alexey A. Ivanov updated HARMONY-2777: -------------------------------------- Attachment: H2777-AbstractDocument.patch The fix: added explicit throwing of NPE to getStartOffset() and getEndOffset() methods. > [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 > Attachments: H2777-AbstractDocument.patch, H2777-AbstractDocument_BranchElementTest.patch > > > 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