harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ch...@apache.org
Subject svn commit: r1028681 - in /harmony/enhanced/java/trunk/classlib/modules/sql/src: main/java/java/sql/Timestamp.java test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Date Fri, 29 Oct 2010 10:53:40 GMT
Author: chope
Date: Fri Oct 29 10:53:39 2010
New Revision: 1028681

URL: http://svn.apache.org/viewvc?rev=1028681&view=rev
Log:
Add fix to allow overriding of the Timestamp class to create an immutable class, by removing
a call to a public method in the Timestamp constructor.  Regression testcase included.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/sql/src/main/java/java/sql/Timestamp.java
    harmony/enhanced/java/trunk/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/sql/src/main/java/java/sql/Timestamp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/sql/src/main/java/java/sql/Timestamp.java?rev=1028681&r1=1028680&r2=1028681&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/sql/src/main/java/java/sql/Timestamp.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/sql/src/main/java/java/sql/Timestamp.java
Fri Oct 29 10:53:39 2010
@@ -353,7 +353,9 @@ public class Timestamp extends Date {
             milliseconds = 1000 + milliseconds;
         }
         super.setTime(theTime);
-        setNanos(milliseconds * 1000000);
+        // bounds checking not required as the value will be
+        // between 0 and 999999999 from the construction
+        nanos = milliseconds * 1000000;
     }
 
     /**

Modified: harmony/enhanced/java/trunk/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java?rev=1028681&r1=1028680&r2=1028681&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Fri Oct 29 10:53:39 2010
@@ -679,4 +679,16 @@ public class TimestampTest extends TestC
     protected void tearDown(){
     	TimeZone.setDefault(defaultTimeZone);
     }
+
+    /**
+     * @tests overriding Timestamp to create an immutable class.
+     */
+    public void testOverridingTimestamp() {
+        Timestamp ts = new Timestamp(8392418){
+            @Override
+            public void setNanos(int n) {
+                throw new RuntimeException("Overridden method shouldn't be called");
+            }
+        };
+    }
 } // end class TimestampTest



Mime
View raw message