harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r400008 - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/ test/java/org/apache/harmony/text/tests/java/text/
Date Fri, 05 May 2006 07:55:48 GMT
Author: mloenko
Date: Fri May  5 00:55:46 2006
New Revision: 400008

URL: http://svn.apache.org/viewcvs?rev=400008&view=rev
Log:
fixes for HARMONY-241
new java.text.RuleBasedCollator((String)null) throws incorrect exception

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/RuleBasedCollator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java?rev=400008&r1=400007&r2=400008&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
Fri May  5 00:55:46 2006
@@ -89,11 +89,13 @@
 	 * @see TextAttribute.RUN_DIRECTION
 	 */
 	public Bidi(AttributedCharacterIterator paragraph) {
-		/*
-		 * TODO: dependency on java.awt.font.TextAttribute and
-		 * java.awt.font.NumericShaper which is not implemented yet.
-		 */
-	}
+        if (paragraph == null)
+            throw new IllegalArgumentException("paragraph is null");
+        /*
+         * TODO: dependency on java.awt.font.TextAttribute and
+         * java.awt.font.NumericShaper which is not implemented yet.
+         */
+    }
 
 	/**
 	 * Create a Bidi object.

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/RuleBasedCollator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/RuleBasedCollator.java?rev=400008&r1=400007&r2=400008&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/RuleBasedCollator.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/RuleBasedCollator.java
Fri May  5 00:55:46 2006
@@ -15,6 +15,8 @@
 
 package java.text;
 
+import org.apache.harmony.luni.util.Msg;
+
 
 /**
  * <code>RuleBasedCollator</code> is a concrete subclass of
@@ -53,9 +55,16 @@
 	 *             when the rules contains an invalid collation rule syntax.
 	 */
 	public RuleBasedCollator(String rules) throws ParseException {
-		try {
-			this.icuColl = new com.ibm.icu.text.RuleBasedCollator(rules);
-		} catch (Exception e) {
+        if (rules == null) {
+            throw new NullPointerException();
+        }
+        if (rules.length() == 0) {
+            throw new ParseException(Msg.getString("K034b"), 0);
+        }
+
+        try {
+            this.icuColl = new com.ibm.icu.text.RuleBasedCollator(rules);
+        } catch (Exception e) {
 			if (e instanceof ParseException) {
 				throw (ParseException) e;
 			}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java?rev=400008&r1=400007&r2=400008&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
Fri May  5 00:55:46 2006
@@ -15,10 +15,8 @@
 
 package org.apache.harmony.text.tests.java.text;
 
-import java.text.AttributedString;
 import java.text.Bidi;
 import java.util.Arrays;
-import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -59,6 +57,13 @@
 		} catch (IllegalArgumentException e) {
 			// expected
 		}
+
+		try {
+            bd = new Bidi(null);
+            fail("should throw IAE");
+        } catch (IllegalArgumentException e) {
+            assertEquals("paragraph is null", e.getMessage());
+        }
 
 		bd = new Bidi("a".toCharArray(), 0, null, 0, 1,
 				Bidi.DIRECTION_RIGHT_TO_LEFT);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java?rev=400008&r1=400007&r2=400008&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
Fri May  5 00:55:46 2006
@@ -228,7 +228,7 @@
         Object obj2 = "b";
         assertEquals(-1, coll.compare(obj1, obj2));
 
-        Collator coll2 = Collator.getInstance();
+        Collator.getInstance();
         assertFalse(coll.equals("A", "\uFF21"));
     }
 
@@ -244,7 +244,7 @@
         Collator coll = Collator.getInstance(Locale.US);
         String text = "abc";
         CollationKey key = coll.getCollationKey(text);
-        int hashCode = key.hashCode();
+        key.hashCode();
 
         CollationKey key2 = coll.getCollationKey("abc");
 
@@ -253,6 +253,34 @@
         assertEquals(0, key.compareTo(key3));
         assertTrue(key.equals(key2));
 
-        byte[] bytes = key.toByteArray();
+        key.toByteArray();
     }
-}
+
+    /**
+     * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
+     */
+    public void testNullPointerException() throws Exception {
+        //Regression for HARMONY-241
+        try {
+            new RuleBasedCollator(null);
+            fail("Constructor RuleBasedCollator(null) "
+                    + "should throw NullPointerException");
+        } catch (NullPointerException e) {}
+    }
+
+    /**
+     * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
+     */
+    public void testEmptyStringException() {
+        //Regression for HARMONY-241
+        try {
+            new RuleBasedCollator("");
+            fail("Constructor RuleBasedCollator(\"\") "
+                    + "should throw ParseException");
+        } catch (ParseException e) {
+            assertEquals("java.text.ParseException", e.getClass().getName());
+            assertEquals(0, e.getErrorOffset());
+        }
+    }
+
+}
\ No newline at end of file



Mime
View raw message