harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r490298 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLClassLoader.java test/java/tests/api/java/net/URLClassLoaderTest.java
Date Tue, 26 Dec 2006 13:55:39 GMT
Author: apetrenko
Date: Tue Dec 26 05:55:38 2006
New Revision: 490298

URL: http://svn.apache.org/viewvc?view=rev&rev=490298
Log:
Patch for HARMONY-2871 "[classlib][luni] URLClassLoader invalidates it's state if there is
invalid URLs in its urls list"

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=490298&r1=490297&r2=490298
==============================================================================
--- 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 Dec 26 05:55:38 2006
@@ -33,6 +33,7 @@
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.IdentityHashMap;
 import java.util.List;
@@ -64,6 +65,8 @@
 
     URL[] urls, orgUrls;
 
+    HashSet invalidUrls = new HashSet();
+
     private IdentityHashMap<URL, JarFile> resCache = new IdentityHashMap<URL, JarFile>(32);
 
     private URLStreamHandlerFactory factory;
@@ -245,12 +248,10 @@
     Vector<URL> findResources(URL[] searchURLs, String name, Vector<URL> result)
{
         boolean findInExtensions = searchURLs == urls;
         for (int i = 0; i < searchURLs.length; i++) {
-            if (searchURLs[i] != null) {
+            if (!invalidUrls.contains(searchURLs[i])) {
                 URL[] search = new URL[] { searchURLs[i] };
                 URL res = findResourceImpl(search, name);
-                if (search[0] == null) {
-                    searchURLs[i] = null;
-                } else {
+                if (!invalidUrls.contains(search[0])) {
                     if (res != null && !result.contains(res)) {
                         result.addElement(res);
                     }
@@ -360,9 +361,7 @@
                     URL[] search = new URL[] { newExtensions[k] };
                     if (resources != null) {
                         URL res = findResourceImpl(search, name);
-                        if (search[0] == null) { // the URL does not exist
-                            newExtensions[k] = null;
-                        } else {
+                        if (!invalidUrls.contains(search[0])) { // the URL does not exist
                             if (res != null && !resources.contains(res)) {
                                 resources.addElement(res);
                             }
@@ -379,9 +378,7 @@
                         if (result != null) {
                             return result;
                         }
-                        if (search[0] == null) { // the URL does not exist
-                            newExtensions[k] = null;
-                        } else {
+                        if (!invalidUrls.contains(search[0])) { // the URL exists
                             result = findInExtensions(explore(newExtensions[k],
                                     i), name, i, null, url);
                             if (result != null) {
@@ -694,7 +691,9 @@
         boolean findInExtensions = searchList == urls;
         int i = 0;
         while (i < searchList.length) {
-            if (searchList[i] != null) {
+            if (searchList[i] == null) {
+                throw new NullPointerException("One of urls is null");
+            } else if(!invalidUrls.contains(searchList[i])) {
                 JarFile jf = null;
                 try {
                     URL currentUrl = searchList[i];
@@ -717,7 +716,7 @@
                                 resCache.put(currentUrl, jf);
                             } catch (IOException e) {
                                 // Don't look for this jar file again
-                                searchList[i] = null;
+                                invalidUrls.add(searchList[i]);
                                 throw e;
                             }
                         }
@@ -729,7 +728,7 @@
                             int sepIdx = file.lastIndexOf("!/");
                             if (sepIdx == -1) {
                                 // Invalid URL, don't look here again
-                                searchList[i] = null;
+                                invalidUrls.add(searchList[i]);
                                 continue;
                             }
                             sepIdx += 2;
@@ -989,6 +988,9 @@
         final String name = new StringBuffer(clsName.replace('.', '/')).append(
                 ".class").toString(); //$NON-NLS-1$
         for (int i = 0; i < searchURLs.length; i++) {
+            if (searchURLs[i] == null) {
+                throw new NullPointerException("One of urls is null");
+            } else if(!invalidUrls.contains(searchURLs[i])) {
             Manifest manifest = null;
             InputStream is = null;
             JarEntry entry = null;
@@ -1013,7 +1015,7 @@
                             resCache.put(thisURL, jf);
                         } catch (IOException e) {
                             // Don't look for this jar file again
-                            searchURLs[i] = null;
+                            invalidUrls.add(searchURLs[i]);
                             throw e;
                         }
                     }
@@ -1024,7 +1026,7 @@
                         int sepIdx = file.lastIndexOf("!/");
                         if (sepIdx == -1) {
                             // Invalid URL, don't look here again
-                            searchURLs[i] = null;
+                            invalidUrls.add(searchURLs[i]);
                             continue;
                         }
                         sepIdx += 2;
@@ -1152,6 +1154,7 @@
                         return c;
                     }
                 }
+            }
             }
         }
         return null;

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=490298&r1=490297&r2=490298
==============================================================================
--- 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 Dec 26 05:55:38 2006
@@ -311,6 +311,22 @@
         } catch (NullPointerException npe) {
             // Expected
         }
+
+        // Regression test for HARMONY-2871.
+        URLClassLoader cl = new URLClassLoader(new URL[] { new URL("file:/foo.jar") });
+
+        try {
+            Class.forName("foo.Foo", false, cl);
+        } catch (Exception ex) {
+            // Don't care
+        }
+
+        try {
+            Class.forName("foo.Foo", false, cl);
+            fail("NullPointerException should be thrown");
+        } catch (ClassNotFoundException cnfe) {
+            // Expected
+        }
     }
 
     /**



Mime
View raw message