harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r771574 - in /harmony/enhanced/classlib/trunk/modules/sql: META-INF/MANIFEST.MF src/main/java/java/sql/Timestamp.java src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Date Tue, 05 May 2009 06:10:25 GMT
Author: regisxu
Date: Tue May  5 06:10:25 2009
New Revision: 771574

URL: http://svn.apache.org/viewvc?rev=771574&view=rev
Log:
Apply patch for HARMONY-6144: [classlib][sql] java.sql.Timestamp.valueOf(String s) should
throw java.lang.IllegalArgumentException if the given string isn't in yyyy-mm-dd hh:mm:ss.fffffffff
format

and also add java.util.regex to import-package in MANIFEST.MF of sql module

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF?rev=771574&r1=771573&r2=771574&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF Tue May  5 06:10:25 2009
@@ -24,6 +24,7 @@
  java.util.jar;resolution:=optional,
  java.util.logging,
  java.util.zip;resolution:=optional,
+ java.util.regex,
  javax.naming,
  javax.xml.parsers;resolution:=optional,
  javax.xml.transform,

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java?rev=771574&r1=771573&r2=771574&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java Tue
May  5 06:10:25 2009
@@ -17,10 +17,10 @@
 
 package java.sql;
 
-import java.text.DecimalFormat;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.regex.Pattern;
 
 import org.apache.harmony.sql.internal.nls.Messages;
 
@@ -50,6 +50,9 @@
     // The nanoseconds time value of the Timestamp
     private int nanos;
 
+    // The regex pattern of yyyy-mm-dd hh:mm:ss
+    private static final String TIME_FORMAT_REGEX = "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.*";
//$NON-NLS-1$
+
     /**
      * Returns a {@code Timestamp} corresponding to the time specified by the
      * supplied values for <i>Year</i>, <i>Month</i>, <i>Date</i>,
<i>Hour</i>,
@@ -410,6 +413,9 @@
 
         // omit trailing whitespaces
         s = s.trim();
+        if (!Pattern.matches(TIME_FORMAT_REGEX, s)) {
+            throw new IllegalArgumentException(Messages.getString("sql.2")); //$NON-NLS-1$
+        }
 
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$
         ParsePosition pp = new ParsePosition(0);

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java?rev=771574&r1=771573&r2=771574&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Tue May  5 06:10:25 2009
@@ -21,9 +21,10 @@
 import java.util.Date;
 import java.util.TimeZone;
 
-import org.apache.harmony.testframework.serialization.SerializationTest;
 import junit.framework.TestCase;
 
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
 /**
  * JUnit Testcase for the java.sql.Timestamp class
  * 
@@ -375,6 +376,30 @@
 
     } // end method testValueOfString
 
+    public void testValueOf_IAE() {
+        try {
+            java.sql.Timestamp.valueOf("2008-12-22 15:00:01.");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+
+        try {
+            // bug of RI 5, passed on RI 6
+            java.sql.Timestamp.valueOf("178548938-12-22 15:00:01.000000001");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+
+        try {
+            java.sql.Timestamp.valueOf("2008-12-22 15:00:01.0000000011");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+    }
+
     /*
      * Method test for toString
      */



Mime
View raw message