harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r934674 - in /harmony/enhanced/java/branches/java6/classlib/modules/luni/src: main/java/java/util/Properties.java test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
Date Fri, 16 Apr 2010 02:53:10 GMT
Author: zhoukevin
Date: Fri Apr 16 02:53:10 2010
New Revision: 934674

URL: http://svn.apache.org/viewvc?rev=934674&view=rev
Log:
Properties.load(InputStream) should not invoke Properties.load(Reader) directly, it may cause
test failure on sub class of Properties, which overrides Properties.load(Reader) method 

Modified:
    harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/Properties.java
    harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java

Modified: harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/Properties.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/Properties.java?rev=934674&r1=934673&r2=934674&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/Properties.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/Properties.java
Fri Apr 16 02:53:10 2010
@@ -274,9 +274,9 @@ public class Properties extends Hashtabl
         bis.reset();
 
         if(!isEbcdic){
-            load(new InputStreamReader(bis, "ISO8859-1")); //$NON-NLS-1$
+            loadImpl(new InputStreamReader(bis, "ISO8859-1")); //$NON-NLS-1$
         }else{
-            load(new InputStreamReader(bis)); //$NON-NLS-1$
+            loadImpl(new InputStreamReader(bis)); //$NON-NLS-1$
         }
     }
 
@@ -295,12 +295,12 @@ public class Properties extends Hashtabl
         //in this case, it should be no harm to read it in default charset
         return false;
     }
-    
+
     /**
      * Loads properties from the specified InputStream. The properties are of
      * the form <code>key=value</code>, one property per line. It may be not
-     * encode as 'ISO-8859-1'.The {@code Properties} file is interpreted according to the
-     * following rules:
+     * encode as 'ISO-8859-1'.The {@code Properties} file is interpreted
+     * according to the following rules:
      * <ul>
      * <li>Empty lines are ignored.</li>
      * <li>Lines starting with either a "#" or a "!" are comment lines and are
@@ -325,6 +325,10 @@ public class Properties extends Hashtabl
      * @since 1.6
      */
     public synchronized void load(Reader reader) throws IOException {
+        loadImpl(reader);
+    }
+
+    private void loadImpl(Reader reader) throws IOException {
         int mode = NONE, unicode = 0, count = 0;
         char nextChar, buf[] = new char[40];
         int offset = 0, keyLength = -1, intVal;

Modified: harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java?rev=934674&r1=934673&r2=934674&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
Fri Apr 16 02:53:10 2010
@@ -25,7 +25,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.PrintWriter;
-import java.io.StringReader;
+import java.io.Reader;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1026,6 +1026,30 @@ public class PropertiesTest extends juni
         assertFalse(nameIterator.hasNext());
     }
 
+    public static class MockProperties extends Properties {
+
+        private static final long serialVersionUID = 1L;
+
+        public MockProperties() throws IOException {
+            mockLoad();
+        }
+
+        private void mockLoad() throws IOException {
+            super.load(new ByteArrayInputStream("key=value".getBytes()));
+        }
+
+        public void load(Reader reader) {
+            fail("should invoke Properties.load(Reader)");
+        }
+    }
+
+    public void test_loadLjava_io_InputStream_onLjava_io_Reader()
+            throws IOException {
+        MockProperties mockProperties = new MockProperties();
+        assertEquals(1, mockProperties.size());
+        assertEquals("value", mockProperties.get("key"));
+    }
+
     /**
      * Sets up the fixture, for example, open a network connection. This method
      * is called before a test is executed.



Mime
View raw message