You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2009/01/12 03:26:22 UTC

svn commit: r733583 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/java/sql/Timestamp.java test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java

Author: qiuxx
Date: Sun Jan 11 18:26:22 2009
New Revision: 733583

URL: http://svn.apache.org/viewvc?rev=733583&view=rev
Log:
Contructor of java.sql.Timestamp should not invoke a public API to initialize, since it may be overrided by subclass which leads to access uninitialized members. Replace the API invoking with private one.

Modified:
    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/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=733583&r1=733582&r2=733583&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 Sun Jan 11 18:26:22 2009
@@ -96,7 +96,7 @@
          * Now set the time for this Timestamp object - which deals with the
          * nanosecond value as well as the base time
          */
-        this.setTime(theTime);
+        setTimeImpl(theTime);
     }
 
     /**
@@ -279,6 +279,10 @@
      */
     @Override
     public void setTime(long theTime) {
+        setTimeImpl(theTime);
+    }
+    
+    private void setTimeImpl(long theTime) {
         /*
          * Deal with the nanoseconds value. The supplied time is in milliseconds -
          * so we must extract the milliseconds value and multiply by 1000000 to

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=733583&r1=733582&r2=733583&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 Sun Jan 11 18:26:22 2009
@@ -30,6 +30,22 @@
  */
 
 public class TimestampTest extends TestCase {
+    
+    static class MockTimestamp extends Timestamp{
+        private String holiday;
+
+        public MockTimestamp(long theTime) {
+            super(theTime);
+            holiday = "Christmas";
+        }
+        
+        // Constructor should not call this public API,
+        // since it may be overrided to use variables uninitialized.
+        public void setTime(long theTime){
+            super.setTime(theTime);
+            holiday.hashCode();
+        }
+    }
 
     static long TIME_TEST1 = 38720231; // 10:45:20.231 GMT
 
@@ -121,9 +137,11 @@
      */
     public void testTimestamplong() {
         Timestamp theTimestamp = new Timestamp(TIME_TEST1);
-
         // The Timestamp should have been created
         assertNotNull(theTimestamp);
+        
+        Timestamp mockTimestamp = new MockTimestamp(TIME_TEST1);
+        assertNotNull(theTimestamp);
     } // end method testTimestamplong
 
     /*