harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r520982 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLClassLoader.java test/java/tests/api/java/net/URLClassLoaderTest.java
Date Wed, 21 Mar 2007 19:50:14 GMT
Author: ayza
Date: Wed Mar 21 12:50:13 2007
New Revision: 520982

URL: http://svn.apache.org/viewvc?view=rev&rev=520982
Log:
Applying fix for URLClassLoader and a new test for URLClassLoaderTest. Inspired by HARMONY-3461
([classlib][net] URLClassLoader cannot find a resource if a file name contains whitespaces).

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java?view=diff&rev=520982&r1=520981&r2=520982
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
Wed Mar 21 12:50:13 2007
@@ -709,6 +709,7 @@
                 try {
                     URL currentUrl = searchList[i];
                     String protocol = currentUrl.getProtocol();
+                    
                     if (protocol.equals("jar")) { //$NON-NLS-1$
                         jf = resCache.get(currentUrl);
                         if (jf == null) {
@@ -787,7 +788,15 @@
                             fixedResName = fixedResName.substring(1);
                         }
                         buf.append(fixedResName);
+
                         String filename = buf.toString();
+                        
+                        try {
+                            filename = URLDecoder.decode(filename, "UTF-8"); //$NON-NLS-1$
+                        } catch (IllegalArgumentException e) {
+                            return null;
+                        }
+
                         if (new File(filename).exists()) {
                             return targetURL(currentUrl, fixedResName);
                         }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java?view=diff&rev=520982&r1=520981&r2=520982
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java
Wed Mar 21 12:50:13 2007
@@ -359,6 +359,26 @@
         assertTrue("Returned incorrect resource", !sb.toString().equals(
                 "This is a test resource file"));
     }
+    
+    public void testFindResource_H3461() throws Exception {
+        File userDir = new File(System.getProperty("user.dir"));
+        File dir = new File(userDir, "encode#me");
+        File f;
+        URLClassLoader loader;
+        
+        if (!dir.exists()) {
+            dir.mkdir();
+        }
+        f = File.createTempFile("temp", ".dat", dir);
+        f.deleteOnExit();
+        dir.deleteOnExit();
+        loader = new URLClassLoader(
+                new URL[] { new URL("file:" + userDir.getAbsolutePath() +
+                        "/encode%23me/") });
+                
+        assertNotNull("Unable to load resource with problematic name",
+            loader.getResource(f.getName()));
+    }
 
     /**
      * @tests java.net.URLClassLoader#getResource(java.lang.String)



Mime
View raw message