harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r440002 - 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, 04 Sep 2006 09:57:18 GMT
Author: pyang
Date: Mon Sep  4 02:57:17 2006
New Revision: 440002

URL: http://svn.apache.org/viewvc?view=rev&rev=440002
Log:
Patch applied for HARMONY-1354([classlib][text] unexpected NPE for AttributedString(AttributedCharacterIterator,
0, 0)) and HARMONY-1355([classlib][text] unexpected OOM for AttributedString(AttributedCharacterIterator))

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=440002&r1=440001&r2=440002
==============================================================================
--- 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  4 02:57:17 2006
@@ -399,13 +399,19 @@
     }
 
     public AttributedString(AttributedCharacterIterator iterator) {
+        if (iterator.getBeginIndex() > iterator.getEndIndex()) {
+        	throw new IllegalArgumentException("Invalid substring range");
+        }
         StringBuffer buffer = new StringBuffer();
-        while (iterator.current() != CharacterIterator.DONE) {
+        for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); i++) { 
             buffer.append(iterator.current());
             iterator.next();
         }
         text = buffer.toString();
         Set<AttributedCharacterIterator.Attribute> attributes = iterator.getAllAttributeKeys();
+        if (attributes == null) {
+        	return;
+        }
         attributeMap = new HashMap<Attribute, List<Range>>((attributes.size()
* 4 / 3) + 1);
 
         Iterator<Attribute> it = attributes.iterator();
@@ -428,6 +434,10 @@
             Set<Attribute> attributes) {
         if (start < iterator.getBeginIndex() || end > iterator.getEndIndex() || start
> end) {
             throw new IllegalArgumentException();
+        }
+        
+        if(attributes == null){
+            return;
         }
 
         StringBuffer buffer = new StringBuffer();

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=440002&r1=440001&r2=440002
==============================================================================
--- 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  4 02:57:17 2006
@@ -17,6 +17,8 @@
 import java.text.AttributedCharacterIterator;
 import java.text.AttributedString;
 import java.text.CharacterIterator;
+import java.util.Map;
+import java.util.Set;
 
 public class AttributedStringTest extends junit.framework.TestCase {
 
@@ -33,6 +35,81 @@
 		while ((ch = it.next()) != CharacterIterator.DONE)
 			buf.append(ch);
 		assertTrue("Wrong string: " + buf, buf.toString().equals(test));
+	}
+
+	/**
+	 * @tests java.text.AttributedString#AttributedString(AttributedCharacterIterator)
+	 */
+	public void test_ConstructorLAttributedCharacterIterator() {
+		//Regression for HARMONY-1354
+		assertNotNull(new AttributedString(new testAttributedCharacterIterator()));
+	}
+	/**
+	 * @tests java.text.AttributedString#AttributedString(AttributedCharacterIterator, int,
int)
+	 */
+	public void test_ConstructorLAttributedCharacterIteratorII() {
+		//Regression for HARMONY-1355
+		assertNotNull(new AttributedString(new testAttributedCharacterIterator(), 0, 0));
+	}
+
+	private class testAttributedCharacterIterator implements AttributedCharacterIterator {
+	    public Set getAllAttributeKeys() {
+	        return null;
+	    }
+	    public Object getAttribute(AttributedCharacterIterator.Attribute p) {
+	        return null;
+	    }
+	    public Map getAttributes() {
+	        return null;
+	    }
+	    public int getRunLimit(Set p) {
+	        return 0;
+	    }
+	    public int getRunLimit(AttributedCharacterIterator.Attribute p) {
+	        return 0;
+	    }
+	    public int getRunLimit() {
+	        return 0;
+	    }
+	    public int getRunStart(Set p) {
+	        return 0;
+	    }
+	    public int getRunStart(AttributedCharacterIterator.Attribute p) {
+	        return 0;
+	    }
+	    public int getRunStart() {
+	        return 0;
+	    }
+	    public Object clone() {
+	        return null;
+	    }
+	    public int getIndex() {
+	        return 0;
+	    }
+	    public int getEndIndex() {
+	        return 0;
+	    }
+	    public int getBeginIndex() {
+	        return 0;
+	    }
+	    public char setIndex(int p) {
+	        return 'a';
+	    }
+	    public char previous() {
+	        return 'a';
+	    }
+	    public char next() {
+	        return 'a';
+	    }
+	    public char current() {
+	        return 'a';
+	    }
+	    public char last() {
+	        return 'a';
+	    }
+	    public char first() {
+	        return 'a';
+	    }
 	}
 
     public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_ObjectII()
{



Mime
View raw message