harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r812342 - in /harmony/enhanced/classlib/branches/java6/modules: luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ text/src/main/java/java/text/ text/src/main/java/org/apache/harmony/text/internal/nls/ text/src/test/java/org/ap...
Date Tue, 08 Sep 2009 04:55:19 GMT
Author: regisxu
Date: Tue Sep  8 04:55:17 2009
New Revision: 812342

URL: http://svn.apache.org/viewvc?rev=812342&view=rev
Log:
Apply patch for HARMONY-6337: [java6][classlib][text] DateFormatSymbols.setZoneStrings should
throw IllegalArgumentException on short arrays

Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
    harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
    harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties
    harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java?rev=812342&r1=812341&r2=812342&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
Tue Sep  8 04:55:17 2009
@@ -186,8 +186,8 @@
 		CALENDAR.set(Calendar.MILLISECOND, 553);
 		DATEFORM.setCalendar(CALENDAR);
 		java.text.DateFormatSymbols symbols = new java.text.DateFormatSymbols();
-		symbols.setZoneStrings(new String[][] { { "a", "b", "c", "d" },
-				{ "e", "f", "g", "h" } });
+		symbols.setZoneStrings(new String[][] { { "a", "b", "c", "d", "e" },
+				{ "f", "g", "h", "i", "j" } });
 		((java.text.SimpleDateFormat) DATEFORM).setDateFormatSymbols(symbols);
 		DATEFORM.setNumberFormat(new java.text.DecimalFormat("#.#;'-'#.#"));
 		DATEFORM.setTimeZone(TimeZone.getTimeZone("EST"));

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java?rev=812342&r1=812341&r2=812342&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
Tue Sep  8 04:55:17 2009
@@ -28,6 +28,7 @@
 import java.util.Set;
 
 import org.apache.harmony.text.LocaleServiceProviderLoader;
+import org.apache.harmony.text.internal.nls.Messages;
 
 /**
  * Encapsulates localizable date-time formatting data, such as the names of the
@@ -533,6 +534,19 @@
      *            the two-dimensional array of strings.
      */
     public void setZoneStrings(String[][] data) {
+        validateZoneStrings(data);
         zoneStrings = data.clone();
     }
+
+    /**
+     * Check that each row in the 2D array is at least length 5
+     * 
+     * @param data
+     * @throws IllegalArgumentException if array contains a short row
+     */
+    private void validateZoneStrings(String[][] data) {
+        for (String[] row : data)
+            if (row.length < 5)
+                throw new IllegalArgumentException(Messages.getString("text.1B"));
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties?rev=812342&r1=812341&r2=812342&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties
Tue Sep  8 04:55:17 2009
@@ -43,4 +43,5 @@
 text.18=Not a valid {0}, subclass should override readResolve()
 text.19=Unparseable date: {0}
 text.1A=position is null
+text.1B=All rows in time zone array must have length at least 5
 

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java?rev=812342&r1=812341&r2=812342&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
Tue Sep  8 04:55:17 2009
@@ -345,7 +345,8 @@
     public void test_getZoneStrings() {
         // Test for method java.lang.String [][]
         // java.text.DateFormatSymbols.getZoneStrings()
-        String[][] val = { { "XX" }, { "YY" } };
+        String[][] val = { { "XX", "XX", "XX", "XX", "XX" }, 
+                { "YY", "YY", "YY", "YY", "YY" } };
         dfs.setZoneStrings(val);
         String[][] retVal = dfs.getZoneStrings();
         if (retVal.length != val.length)
@@ -488,21 +489,59 @@
     public void test_setZoneStrings$$Ljava_lang_String() {
         // Test for method void
         // java.text.DateFormatSymbols.setZoneStrings(java.lang.String [][])
-        String[][] val = { { "XX" }, { "YY" } };
+        String[][] val = { { "XX", "XX", "XX", "XX", "XX" },
+                        { "YY", "YY", "YY", "YY", "YY" } };
         dfs.setZoneStrings(val);
         String[][] retVal = dfs.getZoneStrings();
         assertTrue("get returns identical", retVal != dfs.getZoneStrings());
         assertTrue("get[0] returns identical", retVal[0] != dfs
                 .getZoneStrings()[0]);
         assertTrue("get returned identical", retVal != val);
-        if (retVal.length != val.length)
-            fail("Returned wrong array");
+        assertEquals("Returned wrong array", val.length, retVal.length);
         for (int i = 0; i < val.length; i++)
             assertTrue("Failed to set strings: " + retVal[i], Arrays.equals(
                     retVal[i], val[i]));
     }
 
     /**
+     * @tests java.text.DateFormatSymbols#setZoneStrings(java.lang.String[][])
+     * 
+     * Tests setting zone strings to invalid values
+     * Regression for HARMONY-6337
+     */
+    public void test_setZoneStrings_invalid() {
+        // failing cases
+        String[][] val1 = null;
+        try {
+            dfs.setZoneStrings(val1);
+            fail("Attempt to set zone strings a null array should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        String[][] val2 = { { "XX", "XX" }, { "YY", "YY" } };
+        try {
+            dfs.setZoneStrings(val2);
+            fail("Attempt to set zone strings to a 2D array that contains one or more "
+                 + "rows of length less than 5 should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected because each subarray has length < 5
+        }
+
+        String[][] val3 = { { "a", "b", "c", "d", "e" },
+                { "a", "b", "c", "d", "e" },
+                { "a", "b", "c", "d" },
+                { "a", "b", "c", "d", "e" } };
+        try {
+            dfs.setZoneStrings(val3);
+            fail("Attempt to set zone strings to a 2D array that contains one or more "
+                 + "rows of length less than 5 should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected because each subarray has length < 5
+        }
+    }
+
+    /**
      * Sets up the fixture, for example, open a network connection. This method
      * is called before a test is executed.
      */



Mime
View raw message