harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r478521 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/ProcessBuilder.java test/java/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java
Date Thu, 23 Nov 2006 09:30:56 GMT
Author: liangyx
Date: Thu Nov 23 01:30:55 2006
New Revision: 478521

URL: http://svn.apache.org/viewvc?view=rev&rev=478521
Log:
apply patch for HARMONY-2256 ([classlib][luni]should throw NPE when put/get a null value to/from
env map.)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ProcessBuilder.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ProcessBuilder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ProcessBuilder.java?view=diff&rev=478521&r1=478520&r2=478521
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ProcessBuilder.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ProcessBuilder.java
Thu Nov 23 01:30:55 2006
@@ -66,7 +66,7 @@
             throw new NullPointerException();
         }
         this.command = command;
-        this.environment = new HashMap<String, String>(System.getenv());
+        this.environment = new ProcessHashMap<String, String>(System.getenv());
     }
 
     /**
@@ -216,4 +216,28 @@
         // TODO implement support for redirectErrorStream
         return process;
     }
+    
+    private class ProcessHashMap<K, V> extends HashMap<K, V> {
+
+        private static final long serialVersionUID = 1L;
+
+        public ProcessHashMap(Map<K, V> env) {
+            super(env);
+        }
+        @Override
+        public V put(K key, V value) {
+            if(key == null || value == null){
+                throw new NullPointerException();
+            }
+            return super.put(key, value);
+        }
+        @Override
+        public V get(Object key) {
+            if(key == null){
+                throw new NullPointerException();
+            }
+            return super.get(key);
+        }
+    }
 }
+

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java?view=diff&rev=478521&r1=478520&r2=478521
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java
Thu Nov 23 01:30:55 2006
@@ -90,6 +90,24 @@
         env.clear();
         env = pb.environment();
         assertTrue(env.isEmpty());
+        try {
+            env.put(null,"");
+            fail("should throw NPE.");
+        } catch (NullPointerException e) {
+            // expected;
+        }
+        try {
+            env.put("",null);
+            fail("should throw NPE.");
+        } catch (NullPointerException e) {
+            // expected;
+        }
+        try {
+            env.get(null);
+            fail("should throw NPE.");
+        } catch (NullPointerException e) {
+            // expected;
+        }
     }
 
     public void testRedirectErrorStream() {



Mime
View raw message