harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r447333 - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/AttributedString.java test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java
Date Mon, 18 Sep 2006 09:08:27 GMT
Author: pyang
Date: Mon Sep 18 02:08:26 2006
New Revision: 447333

URL: http://svn.apache.org/viewvc?view=rev&rev=447333
Log:
Patch applied for HARMONY-1244 ([classlib][text] AttributedString.addAttribute(null, ...)
throws nothing while RI throws NPE)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java?view=diff&rev=447333&r1=447332&r2=447333
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java
Mon Sep 18 02:08:26 2006
@@ -504,6 +504,9 @@
     }
 
     public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value)
{
+        if(null == attribute){
+            throw new NullPointerException();
+        }
         if (text.length() == 0) {
             throw new IllegalArgumentException();
         }
@@ -520,6 +523,9 @@
 
     public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value,
             int start, int end) {
+        if(null == attribute){
+            throw new NullPointerException();
+        }
         if (start < 0 || end > text.length() || start >= end) {
             throw new IllegalArgumentException();
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java?view=diff&rev=447333&r1=447332&r2=447333
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java
Mon Sep 18 02:08:26 2006
@@ -19,6 +19,8 @@
 import java.text.CharacterIterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
+import java.util.WeakHashMap;
 
 public class AttributedStringTest extends junit.framework.TestCase {
 
@@ -134,6 +136,42 @@
             fail("Expected IllegalArgumentException");
         } catch (IllegalArgumentException e) {
             // Expected
+        }
+        
+        // regression for Harmony-1244
+        as = new AttributedString("123", new WeakHashMap());
+        try {
+            as.addAttribute(null, new TreeSet(), 0, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            as.addAttribute(null, new TreeSet(), -1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        } 
+    }
+    
+    /**
+     * @tests java.text.AttributedString.addAttribute(AttributedCharacterIterator, Object)
+     */
+    public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_Object()
{
+        //regression for Harmony-1244
+        AttributedString as = new AttributedString("123", new WeakHashMap());
+        try {
+            as.addAttribute(null, new TreeSet());
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try {
+            as.addAttribute(null, null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
         }
     }
 }



Mime
View raw message