harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r496958 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/ test/api/java/common/javax/swing/text/
Date Wed, 17 Jan 2007 08:21:37 GMT
Author: hindessm
Date: Wed Jan 17 00:21:35 2007
New Revision: 496958

URL: http://svn.apache.org/viewvc?view=rev&rev=496958
Log:
Applying patches from "[#HARMONY-2777] [classlib][swing]
j.s.text.AbstractDocument.BranchElement.get{Start, End}Offset throw
ArrayIndexOutOfBoundsException rather than NPE" (again).  Included the
additional fix to AbstractDocumentTest.java.

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/AbstractDocumentTest.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=496958&r1=496957&r2=496958
==============================================================================
--- 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
Wed Jan 17 00:21:35 2007
@@ -401,6 +401,9 @@
 
         @Override
         public int getEndOffset() {
+            if (elements.length == 0) {
+                throw new NullPointerException();
+            }
             return elements[elements.length - 1].getEndOffset();
         }
 
@@ -412,6 +415,9 @@
 
         @Override
         public int getStartOffset() {
+            if (elements.length == 0) {
+                throw new NullPointerException();
+            }
             return elements[0].getStartOffset();
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java?view=diff&rev=496958&r1=496957&r2=496958
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java
Wed Jan 17 00:21:35 2007
@@ -159,33 +159,20 @@
         assertNull(branch.getElement(0));
         assertNull(branch.getElement(1));
         assertEquals(0, branch.getElementCount());
+
         // Since this branch element has no children yet, it has no start and
         // end offsets. Thus calling get{Start,End}Offset on an empty branch
         // element causes the exception being thrown.
-        if (BasicSwingTestCase.isHarmony()) {
-            // Our implementation
-            try {
-                assertEquals(0, branch.getStartOffset());
-                fail("getStartOffset on an empty BranchElement " + "causes exception");
-            } catch (ArrayIndexOutOfBoundsException e) {
-            }
-            try {
-                assertEquals(1, branch.getEndOffset());
-                fail("getEndOffset on an empty BranchElement causes exception");
-            } catch (ArrayIndexOutOfBoundsException e) {
-            }
-        } else {
-            // Reference implementation
-            try {
-                assertEquals(0, branch.getStartOffset());
-                fail("getStartOffset on an empty BranchElement " + "causes exception");
-            } catch (NullPointerException e) {
-            }
-            try {
-                assertEquals(1, branch.getEndOffset());
-                fail("getEndOffset on an empty BranchElement causes exception");
-            } catch (ArrayIndexOutOfBoundsException e) {
-            }
+        try {
+            assertEquals(0, branch.getStartOffset());
+            fail("getStartOffset is expected to throw NullPointerException");
+        } catch (NullPointerException e) {
+        }
+
+        try {
+            assertEquals(1, branch.getEndOffset());
+            fail("getEndOffset is expected to throw NullPointerException");
+        } catch (NullPointerException e) {
         }
     }
 

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=496958&r1=496957&r2=496958
==============================================================================
--- 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
Wed Jan 17 00:21:35 2007
@@ -243,9 +243,31 @@
         assertEquals(0, par.getStartOffset());
     }
 
+    // Regression for HARMONY-2777
+    public void testGetStartOffsetNoChildren() {
+        par = doc.new BranchElement(null, null);
+        try {
+            par.getStartOffset();
+            fail("NullPointerException is expected");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
     public void testGetEndOffset() {
         assertEquals(15, bidi.getEndOffset());
         assertEquals(15, par.getEndOffset());
+    }
+
+    // Regression for HARMONY-2777
+    public void testGetEndOffsetNoChildren() {
+        par = doc.new BranchElement(null, null);
+        try {
+            par.getEndOffset();
+            fail("NullPointerException is expected");
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
     public void testGetElementCount() {



Mime
View raw message