harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r733581 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Date.java test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
Date Mon, 12 Jan 2009 02:13:11 GMT
Author: qiuxx
Date: Sun Jan 11 18:13:11 2009
New Revision: 733581

URL: http://svn.apache.org/viewvc?rev=733581&view=rev
Log:
Contructor of java.util.Date 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/luni/src/main/java/java/util/Date.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java?rev=733581&r1=733580&r2=733581&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java Sun Jan
11 18:13:11 2009
@@ -138,7 +138,7 @@
      *            the number of milliseconds since Jan. 1, 1970 GMT
      */
     public Date(long milliseconds) {
-        this.setTime(milliseconds);
+        this.milliseconds = milliseconds;
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java?rev=733581&r1=733580&r2=733581&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
Sun Jan 11 18:13:11 2009
@@ -23,7 +23,23 @@
 import java.util.TimeZone;
 
 public class DateTest extends junit.framework.TestCase {
-
+    
+    static class MockDate extends Date{
+        private String holiday;
+
+        public MockDate(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();
+        }
+    }
+    
 	/**
 	 * @tests java.util.Date#Date()
 	 */
@@ -91,7 +107,8 @@
 	 */
 	public void test_ConstructorJ() {
 		// Test for method java.util.Date(long)
-		assertTrue("Used to test", true);
+        Date date = new MockDate(1000L);
+        assertNotNull(date);
 	}
 
 	/**



Mime
View raw message