| commit | f76b4d2e4fe00b2b6f00e5b0aa583eb8a54e056f | [log] [tgz] | 
|---|---|---|
| author | Dr Catherine Victoria Hope <chope@apache.org> | Fri Oct 29 10:53:39 2010 +0000 | 
| committer | Dr Catherine Victoria Hope <chope@apache.org> | Fri Oct 29 10:53:39 2010 +0000 | 
| tree | 2b6e28fd847ba47b1e761919dafb834b82b1c5c8 | |
| parent | 3da0401171a217c621691b29825a7273b1ea6d75 [diff] | 
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. git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk@1028681 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/classlib/modules/sql/src/main/java/java/sql/Timestamp.java b/classlib/modules/sql/src/main/java/java/sql/Timestamp.java index 342baa8..9c558b4 100644 --- a/classlib/modules/sql/src/main/java/java/sql/Timestamp.java +++ b/classlib/modules/sql/src/main/java/java/sql/Timestamp.java
@@ -353,7 +353,9 @@ 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; } /**
diff --git a/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java b/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java index adf39a9..ef1b3b5 100644 --- a/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java +++ b/classlib/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
@@ -679,4 +679,16 @@ 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