You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/06/02 11:20:36 UTC

svn commit: r411104 - in /incubator/harmony/enhanced/classlib/trunk/modules/text: make/common/build.xml src/main/java/java/text/AttributedString.java src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java

Author: mloenko
Date: Fri Jun  2 02:20:36 2006
New Revision: 411104

URL: http://svn.apache.org/viewvc?rev=411104&view=rev
Log:
fixes for HARMONY-527
[classlib][text] java.text.AttributedString.addAttribute() incorrectly handles null value

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml
    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/make/common/build.xml
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml?rev=411104&r1=411103&r2=411104&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml Fri Jun  2 02:20:36 2006
@@ -100,7 +100,6 @@
 
                 <fileset dir="${hy.text.src.test.java}">
                     <include name="**/*Test.java"/>
-                    <exclude name="org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorTest.java"/>
                     <exclude name="org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java"/>
                     <exclude name="org/apache/harmony/text/tests/java/text/CollationKeyTest.java"/>
                     <exclude name="org/apache/harmony/text/tests/java/text/CollatorTest.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?rev=411104&r1=411103&r2=411104&view=diff
==============================================================================
--- 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 Fri Jun  2 02:20:36 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -495,10 +495,15 @@
 
 	public void addAttribute(AttributedCharacterIterator.Attribute attribute,
 			Object value, int start, int end) {
-		if (start < 0 || end > text.length() || start >= end)
-			throw new IllegalArgumentException();
+		if (start < 0 || end > text.length() || start >= end) {
+            throw new IllegalArgumentException();
+        }
 
-		ArrayList<Range> ranges = attributeMap.get(attribute);
+        if (value == null) {
+            return;
+        }
+
+        ArrayList<Range> ranges = attributeMap.get(attribute);
 		if (ranges == null) {
 			ranges = new ArrayList<Range>(1);
 			ranges.add(new Range(start, end, value));

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?rev=411104&r1=411103&r2=411104&view=diff
==============================================================================
--- 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 Fri Jun  2 02:20:36 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,9 +35,28 @@
 		assertTrue("Wrong string: " + buf, buf.toString().equals(test));
 	}
 
-	protected void setUp() {
-	}
+    public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_ObjectII() {
+        AttributedString as = new AttributedString("test");
+        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2,
+                3);
+        AttributedCharacterIterator it = as.getIterator();
+        assertEquals("non-null value limit", 2, it
+                .getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
 
-	protected void tearDown() {
-	}
+        as = new AttributedString("test");
+        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null,
+                2, 3);
+        it = as.getIterator();
+        assertEquals("null value limit", 4, it
+                .getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
+
+        try {
+            as = new AttributedString("test");
+            as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE,
+                    null, -1, 3);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+    }
 }