Author: veithen
Date: Mon Oct 19 21:27:09 2015
New Revision: 1709481

URL: http://svn.apache.org/viewvc?rev=1709481&view=rev
Log:
AXIS2-5729: Fix JarFileClassLoader to handle spaces correctly.

Modified:
    
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/UrlResourceFinder.java
    
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/classloader/JarFileClassLoaderTest.java

Modified: 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/UrlResourceFinder.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/UrlResourceFinder.java?rev=1709481&r1=1709480&r2=1709481&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/UrlResourceFinder.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/classloader/UrlResourceFinder.java
 Mon Oct 19 21:27:09 2015
@@ -20,6 +20,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -185,10 +186,13 @@ public class UrlResourceFinder implement
                     } catch (FileNotFoundException e) {
                         // if this is a file URL, the file doesn't exist 
yet... watch to see if it appears later
                         if ("file".equals(url.getProtocol())) {
-                            File file = new File(url.getPath());
-                            watchedFiles.add(file);
-                            continue;
-
+                            try {
+                                File file = new File(url.toURI());
+                                watchedFiles.add(file);
+                                continue;
+                            } catch (URISyntaxException ex) {
+                                // Ignore; we should never get here
+                            }
                         }
                     } catch (IOException ignored) {
                         // can't seem to open the file... this is most likely 
a bad jar file
@@ -226,7 +230,12 @@ public class UrlResourceFinder implement
             throw new UnsupportedOperationException("Only local file jars are 
supported " + url);
         }
 
-        File file = new File(url.getPath());
+        File file;
+        try {
+            file = new File(url.toURI());
+        } catch (URISyntaxException ex) {
+            throw new IOException("Invalid file URL");
+        }
         if (!file.exists()) {
             throw new FileNotFoundException(file.getAbsolutePath());
         }

Modified: 
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/classloader/JarFileClassLoaderTest.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/classloader/JarFileClassLoaderTest.java?rev=1709481&r1=1709480&r2=1709481&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/classloader/JarFileClassLoaderTest.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/classloader/JarFileClassLoaderTest.java
 Mon Oct 19 21:27:09 2015
@@ -28,6 +28,8 @@ import org.apache.commons.io.FileUtils;
 
 public class JarFileClassLoaderTest extends TestCase {
     private File tmpDir;
+    private File root;
+    private File dirWithSpaces;
     
     @Override
     protected void setUp() throws Exception {
@@ -39,13 +41,17 @@ public class JarFileClassLoaderTest exte
         // outside
         // root/a
         // root/dir/b
+        // dir with spaces
         FileUtils.touch(new File(tmpDir, "outside"));
-        File root = new File(tmpDir, "root");
+        root = new File(tmpDir, "root");
         root.mkdir();
         FileUtils.touch(new File(root, "a"));
         File dir = new File(root, "dir");
         dir.mkdir();
         FileUtils.touch(new File(dir, "b"));
+        dirWithSpaces = new File(tmpDir, "dir with spaces");
+        dirWithSpaces.mkdir();
+        FileUtils.touch(new File(dirWithSpaces, "test"));
     }
 
     @Override
@@ -66,9 +72,16 @@ public class JarFileClassLoaderTest exte
      * @throws Exception
      */
     public void testConfinement() throws Exception {
-        ClassLoader cl = new JarFileClassLoader(new URL[] { new File(tmpDir, 
"root").toURL() });
+        ClassLoader cl = new JarFileClassLoader(new URL[] { 
root.toURI().toURL() });
         assertNull(cl.getResource("../outside"));
         assertNotNull(cl.getResource("a"));
         assertNotNull(cl.getResource("dir/b"));
     }
+    
+    public void testClasspathElementWithSpaces() throws Exception {
+        ClassLoader cl = new JarFileClassLoader(new URL[] { 
dirWithSpaces.toURI().toURL() });
+        URL test = cl.getResource("test");
+        assertNotNull(test);
+        assertEquals(new File(dirWithSpaces, "test"), new File(test.toURI()));
+    }
 }


Reply via email to