harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r505788 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/AbstractDocument.java test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java
Date Sat, 10 Feb 2007 23:08:59 GMT
Author: ayza
Date: Sat Feb 10 15:08:58 2007
New Revision: 505788

URL: http://svn.apache.org/viewvc?view=rev&rev=505788
Log:
Updated version of the patch from HARMONY-2459 ([classlib] [swing] Method replace() in class
AbstractDocument$BranchElement throws NegativeArraySizeException) and patch for the test were
applied

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/AbstractDocument.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/AbstractDocument.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/AbstractDocument.java?view=diff&rev=505788&r1=505787&r2=505788
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/AbstractDocument.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/AbstractDocument.java
Sat Feb 10 15:08:58 2007
@@ -435,8 +435,14 @@
 
         public void replace(final int index, final int length,
                             final Element[] newElements) {
-            Element[] newArray = new Element[elements.length
-                                             - length + newElements.length];
+            Element[] newArray;
+
+            if (index < 0 || length < 0 || elements.length < index + length) {
+                throw new ArrayIndexOutOfBoundsException(); 
+            }
+
+            newArray = new Element[
+                    elements.length - length + newElements.length];
 
             System.arraycopy(elements, 0, newArray, 0, index);
             System.arraycopy(newElements, 0, newArray, index,

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java?view=diff&rev=505788&r1=505787&r2=505788
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java
Sat Feb 10 15:08:58 2007
@@ -333,6 +333,43 @@
          */
     }
 
+    // Regression for HARMONY-2459
+    public void testReplace04() {
+        PlainDocument document = new PlainDocument();
+        Element elem = new DummyElement();
+        AbstractDocument.BranchElement branchElem =
+                document.new BranchElement(elem, (AttributeSet) null);
+        Element[] arr0 = new Element[] {null, null, null};
+
+        try {
+            branchElem.replace(Integer.MIN_VALUE, 5, arr0);
+            fail("ArrayIndexOutOfBoundsException is expected");
+        } catch (ArrayIndexOutOfBoundsException ex) {
+            // valid
+        }
+
+        try {
+            branchElem.replace(0, -1, arr0);
+            fail("ArrayIndexOutOfBoundsException is expected");
+        } catch (ArrayIndexOutOfBoundsException ex) {
+            // valid
+        }
+
+        try {
+            branchElem.replace(1, 5, arr0);
+            fail("ArrayIndexOutOfBoundsException is expected");
+        } catch (ArrayIndexOutOfBoundsException ex) {
+            // valid
+        }
+
+        try {
+            branchElem.replace(0, 2, arr0);
+            fail("ArrayIndexOutOfBoundsException is expected");
+        } catch (ArrayIndexOutOfBoundsException ex) {
+            // valid
+        }
+    }
+
     public void testPositionToElement() {
         assertNull(par.positionToElement(-1));
         assertSame(leaf2, par.positionToElement(7));
@@ -382,4 +419,50 @@
         styledDoc.setCharacterAttributes(13, 5, SimpleAttributeSet.EMPTY, false);
         return (BranchElement)doc.getDefaultRootElement().getElement(1);
     }
+
+    /**
+     * This class is used by testReplace04
+     */
+    class DummyElement implements Element {
+        public AttributeSet getAttributes() {
+            return null;
+        }
+
+        public Document getDocument() {
+            return null;
+        }
+
+        public Element getElement(int p0) {
+            return null;
+        }
+
+        public int getElementCount() {
+            return 0;
+        }
+
+        public int getElementIndex(int p0) {
+            return 0;
+        }
+
+        public int getEndOffset() {
+            return 0;
+        }
+
+        public String getName() {
+            return "AA";
+        }
+
+        public Element getParentElement() {
+            return null;
+        }
+
+        public int getStartOffset() {
+            return 0;
+        }
+
+        public boolean isLeaf() {
+            return false;
+        }
+    }
+
 }



Mime
View raw message