harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r438404 - in /incubator/harmony/enhanced/classlib/trunk/modules/sql/src: main/java/java/sql/ test/java/org/apache/harmony/sql/tests/java/sql/
Date Wed, 30 Aug 2006 07:08:20 GMT
Author: pyang
Date: Wed Aug 30 00:08:20 2006
New Revision: 438404

URL: http://svn.apache.org/viewvc?rev=438404&view=rev
Log:
Patch applied for HARMONY-1305 ([classlib][sql] java.sql.Date.valueOf(String str) method should
throw IllegalArgumentException when the string is "1991-01-01-01") and HARMONY-1307 ([classlib][sql]
java.sql.Time.valueOf(String str) method should throw IllegalArgumentException when the string
is "15:43:12:34".)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java
    incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java
    incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java?rev=438404&r1=438403&r2=438404&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java
Wed Aug 30 00:08:20 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -181,7 +181,7 @@
         if (theString == null) {
             throw new IllegalArgumentException();
         }
-
+        validateString(theString, '-');
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
         try {
             aDate = dateFormat.parse(theString);
@@ -201,4 +201,27 @@
     private static long normalizeTime(long theTime) {
         return theTime;
     }
+    
+    /*
+     * Private method to validate the string. If the string is separated into 
+     * three parts by two separator char,we should check each part of the string.We just
+     * use the first two separator char, the others are treated as normal characters.
+     */
+    static void validateString(String timeString, char sep) {
+        int first = timeString.indexOf(sep); //$NON-NLS-1$
+        int second = timeString.indexOf(sep, first + 1); //$NON-NLS-1$
+        if (second != -1) {
+            //The string is separated into three parts by two separator character,
+            //if the first or the third part is null string, we should
+            //throw IllegalArgumentException to follow RI
+            if (first == 0 || second + 1 == timeString.length()) {
+                throw new IllegalArgumentException();
+            }
+            //check each part of the string
+            Integer.parseInt(timeString.substring(0, first));
+            Integer.parseInt(timeString.substring(first + 1, second));
+            Integer.parseInt(timeString.substring(second + 1, timeString
+                    .length()));
+        }
+    }   
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java?rev=438404&r1=438403&r2=438404&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java
Wed Aug 30 00:08:20 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -178,7 +178,7 @@
         if (theTime == null) {
             throw new IllegalArgumentException();
         }
-
+        java.sql.Date.validateString(theTime, ':');
         SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
         try {
             aDate = dateFormat.parse(theTime);
@@ -188,4 +188,5 @@
 
         return new Time(aDate.getTime());
     }
+
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java?rev=438404&r1=438403&r2=438404&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
Wed Aug 30 00:08:20 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -389,6 +389,74 @@
 		} // end for
 
 	} // end method testValueOf()
+    
+    /**
+     * @tests java.sql.Date#valueOf(String )
+     */
+    public void test_valueOf_IllegalArgumentException() {
+        try{
+            Date.valueOf("1996-10-07-01");
+            fail("should throw NumberFormatException");
+        } catch (NumberFormatException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("-10-07-01");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("--01");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("1991--");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("-01-");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("-10-w2-01");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("07-w2-");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("1997-w2-w2");
+            fail("should throw NumberFormatException");
+        } catch (NumberFormatException e) {
+            //expected
+        }
+        
+        try{
+            Date.valueOf("1996--01");
+            fail("should throw NumberFormatException");
+        } catch (NumberFormatException e) {
+            //expected
+        }
+    }
 
 } // end class DateTest
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java?rev=438404&r1=438403&r2=438404&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
Wed Aug 30 00:08:20 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 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.
@@ -254,6 +254,73 @@
 			 */
 		} // end try
 	} // end method test
-
+    
+    /**
+     * @tests java.sql.Time#valueOf(String )
+     */
+     public void test_valueOf_IllegalArgumentException() {
+            try{
+                Time.valueOf("15:43:12:34");
+                fail("should throw NumberFormatException");
+            } catch (NumberFormatException e) {
+                //expected
+            }
+            
+            try{
+                Time.valueOf(":10:07:01");
+                fail("should throw IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+                //expected
+            }
+            
+            try{
+                Time.valueOf("::01");
+                fail("should throw IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+                //expected
+            }
+            
+            try{
+                Time.valueOf("11::");
+                fail("should throw IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+                //expected
+            }
+            
+            try{
+                Time.valueOf(":01:");
+                fail("should throw IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+                //expected
+            }
+            
+            try{
+                Time.valueOf(":10:w2:01");
+                fail("should throw IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+                //expected
+            }
+        
+            try{
+                Time.valueOf("07:w2:");
+                fail("should throw IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+                //expected
+            }
+            
+            try{
+                Time.valueOf("17:w2:w2");
+                fail("should throw NumberFormatException");
+            } catch (NumberFormatException e) {
+                //expected
+            }
+            
+            try{
+                Time.valueOf("16::01");
+                fail("should throw NumberFormatException");
+            } catch (NumberFormatException e) {
+                //expected
+            }
+        }
 } // end class TimeTest
 



Mime
View raw message