harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r542658 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLClassLoader.java test/java/tests/api/java/net/URLClassLoaderTest.java test/resources/tests/api/java/net/test%.properties
Date Tue, 29 May 2007 21:38:47 GMT
Author: ayza
Date: Tue May 29 14:38:47 2007
New Revision: 542658

URL: http://svn.apache.org/viewvc?view=rev&rev=542658
Log:
Applying slightly corrected version of the patch from HARMONY-2255 ([classlib][luni]ClassLoader.getResourceAsStream
fails to get file whose name with "%")

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/net/test%.properties
  (with props)
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=542658&r1=542657&r2=542658
==============================================================================
--- 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
Tue May 29 14:38:47 2007
@@ -265,7 +265,7 @@
 
         URL findResource(String name) {
             URL resURL = targetURL(url, name);
-            if (resURL!=null) {
+            if (resURL != null) {
                 try {
                     URLConnection uc = resURL.openConnection();
                     uc.getInputStream().close();
@@ -276,7 +276,7 @@
                     }
                     int code;
                     if ((code = ((HttpURLConnection) uc).getResponseCode()) >= 200
-                        && code < 300) {
+                            && code < 300) {
                         return resURL;
                     }
                 } catch (SecurityException e) {
@@ -568,26 +568,31 @@
 
         URL findResource(String name) {
             int idx =0;
+            String filename;
+            
             // Do not create a UNC path, i.e. \\host
             while (idx<name.length() && ((name.charAt(idx)=='/') //$NON-NLS-1$
                    || (name.charAt(idx)=='\\') )) { //$NON-NLS-1$
                 idx++;
             }
-            if(idx>0) {
+
+            if (idx > 0) {
                 name = name.substring(idx);
             }
-            String filename = prefix+name;
+
             try {
-                filename = URLDecoder.decode(filename, "UTF-8"); //$NON-NLS-1$
+                filename = URLDecoder.decode(prefix, "UTF-8") + name; //$NON-NLS-1$
+
+                if (new File(filename).exists()) {
+                    return targetURL(url, name);
+                } else {
+                    return null;
+                }
             } catch (IllegalArgumentException e) {
                 return null;
             } catch (UnsupportedEncodingException e) {
                 return null;
             }
-            if (new File(filename).exists()) {
-                return targetURL(url, name);
-            }
-            return null;
         }
 
     }
@@ -971,13 +976,14 @@
      */
     URL findResourceImpl(String resName) {
         int n = 0;
-        while(true) {
+
+        while (true) {
             URLHandler handler = getHandler(n++);
-            if(handler == null) {
+            if (handler == null) {
                 break;
             }
             URL res = handler.findResource(resName);
-            if(res!=null) {
+            if (res != null) {
                 return res;
             }
         }
@@ -985,23 +991,23 @@
     }
 
     URLHandler getHandler(int num) {
-        if(num < handlerList.size()) {
+        if (num < handlerList.size()) {
             return handlerList.get(num);
         }
         makeNewHandler();
-        if(num < handlerList.size()) {
+        if (num < handlerList.size()) {
             return handlerList.get(num);
         }
         return null;
     }
 
     private synchronized void makeNewHandler() {
-        while(!searchList.isEmpty()) {
+        while (!searchList.isEmpty()) {
             URL nextCandidate = searchList.remove(0);
             if (nextCandidate == null) {  // KA024=One of urls is null
                 throw new NullPointerException(Msg.getString("KA024")); //$NON-NLS-1$
             }
-            if(!handlerMap.containsKey(nextCandidate)) {
+            if (!handlerMap.containsKey(nextCandidate)) {
                 URLHandler result;
                 String protocol = nextCandidate.getProtocol();
                 if (protocol.equals("jar")) { //$NON-NLS-1$
@@ -1011,8 +1017,8 @@
                 } else {
                     result = createURLHandler(nextCandidate);
                 }
-                if(result!=null) {
-                    handlerMap.put(nextCandidate,result);
+                if (result != null) {
+                    handlerMap.put(nextCandidate, result);
                     handlerList.add(result);
                     return;
                 }

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=542658&r1=542657&r2=542658
==============================================================================
--- 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
Tue May 29 14:38:47 2007
@@ -35,9 +35,18 @@
 
 import tests.support.Support_Configuration;
 import tests.support.resource.Support_Resources;
+import junit.framework.TestSuite;
 
 public class URLClassLoaderTest extends junit.framework.TestCase {
 
+    public URLClassLoaderTest() {
+        super();
+    }
+    
+    public URLClassLoaderTest(String s) {
+        super(s);
+    }
+    
     class BogusClassLoader extends ClassLoader {
         public URL getResource(String res) {
             try {
@@ -379,7 +388,7 @@
         f.deleteOnExit();
         f2 = File.createTempFile("bad#name#", ".dat", dir);
         f2.deleteOnExit();
-                
+          
         assertNotNull("Unable to load resource from path with problematic name",
             loader.getResource(f.getName()));
         assertEquals("URL was not correctly encoded",
@@ -445,4 +454,24 @@
         URLClassLoader loader = new URLClassLoader(urls, null);
 		return loader;
 	}
+
+    /**
+     * Regression test for HARMONY-2255
+     */
+    public void test_getResourceAsStream() {
+        InputStream in = this.getClass().getClassLoader().getResourceAsStream(
+                "tests/api/java/net/test%.properties");
+        assertNotNull(in);
+        in = this.getClass().getClassLoader().getResourceAsStream(
+                "tests/api/java/net/test%25.properties");
+        assertNull(in);
+    }
+    
+//    public static TestSuite suite() {
+//        TestSuite suite = new TestSuite();
+//        
+//        suite.addTest(new URLClassLoaderTest("testFindResource_H3461"));
+//        suite.addTest(new URLClassLoaderTest("test_getResourceAsStream"));
+//        return suite;
+//    }
 }

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/net/test%.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/net/test%25.properties?view=auto&rev=542658
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/net/test%.properties
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/net/test%.properties
Tue May 29 14:38:47 2007
@@ -0,0 +1 @@
+mama=rama
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/tests/api/java/net/test%.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message