geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r790743 - /geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ResourceFinder.java
Date Thu, 02 Jul 2009 21:47:42 GMT
Author: dblevins
Date: Thu Jul  2 21:47:42 2009
New Revision: 790743

URL: http://svn.apache.org/viewvc?rev=790743&view=rev
Log:
Patch from viola.lu, XBEAN-133: Jar file is not close after open resulting in files delete
failure when finding resource

Thanks, Viola!

Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ResourceFinder.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ResourceFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ResourceFinder.java?rev=790743&r1=790742&r2=790743&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ResourceFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ResourceFinder.java
Thu Jul  2 21:47:42 2009
@@ -961,8 +961,8 @@
             URL currentUrl = search[i];
             if (currentUrl == null) {
                 continue;
-            }
-            JarFile jarFile = null;
+            }            
+
             try {
                 String protocol = currentUrl.getProtocol();
                 if (protocol.equals("jar")) {
@@ -972,8 +972,10 @@
                     * entry doesn't exist.
                     */
                     URL jarURL = ((JarURLConnection) currentUrl.openConnection()).getJarFileURL();
+                    JarFile jarFile;
+                    JarURLConnection juc;
                     try {
-                        JarURLConnection juc = (JarURLConnection) new URL("jar", "", jarURL.toExternalForm()
+ "!/").openConnection();
+                        juc = (JarURLConnection) new URL("jar", "", jarURL.toExternalForm()
+ "!/").openConnection();
                         jarFile = juc.getJarFile();
                     } catch (IOException e) {
                         // Don't look for this jar file again
@@ -981,29 +983,41 @@
                         throw e;
                     }
 
-                    String entryName;
-                    if (currentUrl.getFile().endsWith("!/")) {
-                        entryName = resourceName;
-                    } else {
-                        String file = currentUrl.getFile();
-                        int sepIdx = file.lastIndexOf("!/");
-                        if (sepIdx == -1) {
-                            // Invalid URL, don't look here again
-                            search[i] = null;
-                            continue;
+                    try {
+                        juc = (JarURLConnection) new URL("jar", "", jarURL.toExternalForm()
+ "!/").openConnection();                        
+                        jarFile = juc.getJarFile();
+                        String entryName;
+                        if (currentUrl.getFile().endsWith("!/")) {
+                            entryName = resourceName;
+                        } else {
+                            String file = currentUrl.getFile();
+                            int sepIdx = file.lastIndexOf("!/");
+                            if (sepIdx == -1) {
+                                // Invalid URL, don't look here again
+                                search[i] = null;
+                                continue;
+                            }
+                            sepIdx += 2;
+                            StringBuffer sb = new StringBuffer(file.length() - sepIdx + resourceName.length());
+                            sb.append(file.substring(sepIdx));
+                            sb.append(resourceName);
+                            entryName = sb.toString();
+                        }
+                        if (entryName.equals("META-INF/") && jarFile.getEntry("META-INF/MANIFEST.MF")
!= null) {
+                            return targetURL(currentUrl, "META-INF/MANIFEST.MF");
+                        }
+                        if (jarFile.getEntry(entryName) != null) {
+                            return targetURL(currentUrl, resourceName);
+                        }
+                    } finally {
+                        if (!juc.getUseCaches()) {
+                            try {
+                                jarFile.close();
+                            } catch (Exception e) {
+                            }
                         }
-                        sepIdx += 2;
-                        StringBuffer sb = new StringBuffer(file.length() - sepIdx + resourceName.length());
-                        sb.append(file.substring(sepIdx));
-                        sb.append(resourceName);
-                        entryName = sb.toString();
-                    }
-                    if (entryName.equals("META-INF/") && jarFile.getEntry("META-INF/MANIFEST.MF")
!= null){
-                        return targetURL(currentUrl, "META-INF/MANIFEST.MF");
-                    }
-                    if (jarFile.getEntry(entryName) != null) {
-                        return targetURL(currentUrl, resourceName);
                     }
+                    
                 } else if (protocol.equals("file")) {
                     String baseFile = currentUrl.getFile();
                     String host = currentUrl.getHost();



Mime
View raw message