harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r790210 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLStreamHandler.java test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
Date Wed, 01 Jul 2009 15:11:09 GMT
Author: tellison
Date: Wed Jul  1 15:11:09 2009
New Revision: 790210

URL: http://svn.apache.org/viewvc?rev=790210&view=rev
Log:
Fix for HARMONY-6254 ([classlib][luni] URLStreamHandler throws NPE when creating external
form)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java?rev=790210&r1=790209&r2=790210&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
Wed Jul  1 15:11:09 2009
@@ -305,8 +305,7 @@
      * @see URL#toExternalForm()
      */
     protected String toExternalForm(URL url) {
-        StringBuilder answer = new StringBuilder(url.getProtocol().length()
-                + url.getFile().length() + 16);
+        StringBuilder answer = new StringBuilder();
         answer.append(url.getProtocol());
         answer.append(':');
         String authority = url.getAuthority();
@@ -317,8 +316,9 @@
 
         String file = url.getFile();
         String ref = url.getRef();
-        // file is never null
-        answer.append(file);
+        if (file != null) {
+            answer.append(file);
+        }
         if (ref != null) {
             answer.append('#');
             answer.append(ref);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java?rev=790210&r1=790209&r2=790210&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
Wed Jul  1 15:11:09 2009
@@ -1234,7 +1234,33 @@
         String ref = "?y";
         URL url = new URL(new URL(strURL), ref);
         assertEquals("http://a/b/c/?y", url.toExternalForm());
+    }
+
+    // Regression test for HARMONY-6254
+
+    // Bogus handler forces file part of URL to be null
+    static class MyHandler2 extends URLStreamHandler {
+
+        @Override
+        protected URLConnection openConnection(URL arg0) throws IOException {
+            return null;
+        }
+
+        @Override
+        protected void setURL(URL u, String protocol, String host, int port,
+                String authority, String userInfo, String file, String query,
+                String ref) {
+            super.setURL(u, protocol, host, port, authority, userInfo,
+                    (String) null, query, ref);
+        }
+    }
 
+    // Test special case of external form with null file part (HARMONY-6254)
+    public void test_toExternalForm_Null() throws IOException {
+        URLStreamHandler myHandler = new MyHandler2();
+        URL url = new URL(null, "foobar://example.com/foobar", myHandler);
+        String s = url.toExternalForm();
+        assertEquals("Got wrong URL external form", "foobar://example.com", s);
     }
 
     static class MockProxySelector extends ProxySelector {



Mime
View raw message