harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r438075 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URL.java test/java/tests/api/java/net/URLTest.java
Date Tue, 29 Aug 2006 13:42:23 GMT
Author: hindessm
Date: Tue Aug 29 06:42:22 2006
New Revision: 438075

URL: http://svn.apache.org/viewvc?rev=438075&view=rev
Log:
Applied patches from "[#HARMONY-1131] [classlib][luni] Compatibility:
java.net.URL(null, String, int, String, URLStreamHandler) does not throw
NPE if protocol==null".

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java?rev=438075&r1=438074&r2=438075&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
Tue Aug 29 06:42:22 2006
@@ -402,7 +402,12 @@
 			host = "[" + host + "]"; //$NON-NLS-1$ //$NON-NLS-2$
 		}
 
-		this.protocol = protocol;
+		if (protocol != null){
+		    this.protocol = protocol;
+        } else {
+            throw new NullPointerException(Msg.getString("K00b3", protocol)); //$NON-NLS-1$
+        }
+        
 		this.host = host;
 		this.port = port;
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java?rev=438075&r1=438074&r2=438075&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
Tue Aug 29 06:42:22 2006
@@ -1178,7 +1178,81 @@
             System.setSecurityManager(null);
         }
     }
+
+    /**
+     * URLStreamHandler implementation class necessary for tests. 
+     */
+    private class TestURLStreamHandler extends URLStreamHandler {
+        public URLConnection openConnection(URL arg0) throws IOException {
+            try {
+                return arg0.openConnection();
+            } catch (Throwable e) {
+                return null;
+            }
+        }
+    }
     
+    /**
+     * Check NPE throwing in constructor when protocol argument is null and
+     * URLStreamHandler argument is initialized.
+     */
+    public void test_ConstructorLnullLjava_lang_StringILjava_lang_StringLjava_net_URLStreamHandler()
+        throws Exception {
+        // Regression for HARMONY-1131
+        TestURLStreamHandler lh = new TestURLStreamHandler();
+
+        try {
+            new URL(null, "1", 0, "file", lh);
+            fail("NullPointerException expected, but nothing was thrown!");
+        } catch (NullPointerException e) {
+            // Expected NullPointerException
+        }
+
+    }
+    
+    /**
+     * Check NPE throwing in constructor when protocol argument is null and
+     * URLStreamHandler argument is null.
+     */
+    public void test_ConstructorLnullLjava_lang_StringILjava_lang_StringLnull()
+        throws Exception {
+        // Regression for HARMONY-1131
+        try {
+            new URL(null, "1", 0, "file", null);
+            fail("NullPointerException expected, but nothing was thrown!");
+        } catch (NullPointerException e) {
+            // Expected NullPointerException
+        }
+    }
+
+    /**
+     * Check NPE throwing in constructor with 4 params when protocol argument is null.
+     */
+    public void test_ConstructorLnullLjava_lang_StringILjava_lang_String()
+        throws Exception {
+        // Regression for HARMONY-1131
+        try {
+            new URL(null, "1", 0, "file");
+            fail("NullPointerException expected, but nothing was thrown!");
+        } catch (NullPointerException e) {
+            // Expected NullPointerException
+        }
+    }
+
+    /**
+     * Check NPE throwing in constructor with 3 params when protocol argument is null.
+     */
+    public void test_ConstructorLnullLjava_lang_StringLjava_lang_String()
+        throws Exception {
+        // Regression for HARMONY-1131
+        try {
+            new URL(null, "1", "file");
+            fail("NullPointerException expected, but nothing was thrown!");
+        } catch (NullPointerException e) {
+            // Expected NullPointerException
+        }
+    }
+
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method
 	 * is called before a test is executed.



Mime
View raw message