harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r502513 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLClassLoader.java test/java/tests/api/java/net/URLClassLoaderTest.java
Date Fri, 02 Feb 2007 06:03:10 GMT
Author: liangyx
Date: Thu Feb  1 22:03:10 2007
New Revision: 502513

URL: http://svn.apache.org/viewvc?view=rev&rev=502513
Log:
Apply patch for HARMONY-2237([classlib][luni]URLClassLoader should not throw NullPointerException
in special cases)

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=502513&r1=502512&r2=502513
==============================================================================
--- 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
Thu Feb  1 22:03:10 2007
@@ -914,9 +914,14 @@
         // Class-path attribute is composed of space-separated values.
         StringTokenizer tokenizer = new java.util.StringTokenizer(classpath);
         Vector<URL> addedURLs = new Vector<URL>();
-        String file = root.getFile();
-        file = file.substring(0, file.lastIndexOf("/", //$NON-NLS-1$
-                file.lastIndexOf("!/") - 1) + 1); //$NON-NLS-1$
+        String file = root.getFile();        
+        int jarIndex = file.lastIndexOf("!/") - 1; //$NON-NLS-1$
+        int index = file.lastIndexOf("/", jarIndex) + 1; //$NON-NLS-1$
+        if (index == 0) {
+			index = file.lastIndexOf(
+					System.getProperty("file.separator"), jarIndex) + 1; //$NON-NLS-1$
+		}
+        file = file.substring(0, index);
         String protocol = root.getProtocol();
         String host = root.getHost();
         int port = root.getPort();

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=502513&r1=502512&r2=502513
==============================================================================
--- 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
Thu Feb  1 22:03:10 2007
@@ -27,6 +27,8 @@
 import java.net.URLStreamHandlerFactory;
 import java.util.Enumeration;
 import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+import java.util.Vector;
 
 import org.apache.harmony.luni.util.InvalidJarIndexException;
 
@@ -382,4 +384,38 @@
         assertTrue("too long. UNC path formed? UNC time: " + uncTime
                 + " regular time: " + time, uncTime <= (time * 4));
     }
+    
+    /**
+	 * Regression for Harmony-2237 
+	 */
+	public void test_getResource() throws Exception {		
+		URLClassLoader urlLoader = getURLClassLoader();
+		assertNull(urlLoader.findResource("XXX")); //$NON-NLS-1$
+	}
+
+	private static URLClassLoader getURLClassLoader() {
+		String classPath = System.getProperty("java.class.path");
+        StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator);
+        Vector<URL> urlVec = new Vector<URL>();
+        String resPackage = Support_Resources.RESOURCE_PACKAGE;
+        try {
+            while (tok.hasMoreTokens()) {
+                String path = tok.nextToken();
+                String url;
+                if (new File(path).isDirectory())
+                    url = "file:" + path + resPackage + "subfolder/";
+                else
+                    url = "jar:file:" + path + "!" + resPackage + "subfolder/";
+                urlVec.addElement(new URL(url));
+            }
+        } catch (MalformedURLException e) {
+        	// do nothing
+        }
+        URL[] urls = new URL[urlVec.size()];
+        for (int i = 0; i < urlVec.size(); i++) {
+        	urls[i] = urlVec.elementAt(i);
+        }            
+        URLClassLoader loader = new URLClassLoader(urls, null);
+		return loader;
+	}
 }



Mime
View raw message