[Bug 394064] ensure that JarFile instances are closed on JarFileResource.release()

This commit is contained in:
Jesse McConnell 2013-02-15 11:59:39 -06:00
parent 2581eb130a
commit cf98276b32
14 changed files with 50 additions and 23 deletions

View File

@ -65,6 +65,19 @@ class JarFileResource extends JarResource
_list=null; _list=null;
_entry=null; _entry=null;
_file=null; _file=null;
if ( _jarFile != null )
{
try
{
_jarFile.close();
}
catch ( IOException ioe )
{
LOG.ignore(ioe);
}
}
_jarFile=null; _jarFile=null;
super.release(); super.release();
} }
@ -166,7 +179,7 @@ class JarFileResource extends JarResource
if (jarFile!=null && _entry==null && !_directory) if (jarFile!=null && _entry==null && !_directory)
{ {
// OK - we have a JarFile, lets look at the entries for our path // OK - we have a JarFile, lets look at the entries for our path
Enumeration e=jarFile.entries(); Enumeration<JarEntry> e=jarFile.entries();
while(e.hasMoreElements()) while(e.hasMoreElements())
{ {
JarEntry entry = (JarEntry) e.nextElement(); JarEntry entry = (JarEntry) e.nextElement();
@ -301,12 +314,11 @@ class JarFileResource extends JarResource
} }
} }
Enumeration e=jarFile.entries(); Enumeration<JarEntry> e=jarFile.entries();
String dir=_urlString.substring(_urlString.indexOf("!/")+2); String dir=_urlString.substring(_urlString.indexOf("!/")+2);
while(e.hasMoreElements()) while(e.hasMoreElements())
{ {
JarEntry entry = e.nextElement();
JarEntry entry = (JarEntry) e.nextElement();
String name=entry.getName().replace('\\','/'); String name=entry.getName().replace('\\','/');
if(!name.startsWith(dir) || name.length()==dir.length()) if(!name.startsWith(dir) || name.length()==dir.length())
{ {

View File

@ -35,8 +35,11 @@ import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.jar.JarFile;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import junit.framework.Assert;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.OS; import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
@ -125,14 +128,14 @@ public class ResourceTest
URI uri = file.toURI(); URI uri = file.toURI();
__userURL=uri.toURL(); __userURL=uri.toURL();
__userURL = new URL(__userURL.toString() + "src/test/java/org/eclipse/jetty/util/resource/"); __userURL = MavenTestingUtils.getTestResourcesDir().toURI().toURL();
FilePermission perm = (FilePermission) __userURL.openConnection().getPermission(); FilePermission perm = (FilePermission) __userURL.openConnection().getPermission();
__userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar; __userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar;
__relDir = "src/test/java/org/eclipse/jetty/util/resource/".replace('/', File.separatorChar); __relDir = "src/test/resources/".replace('/', File.separatorChar);
System.err.println("User Dir="+__userDir); //System.err.println("User Dir="+__userDir);
System.err.println("Rel Dir="+__relDir); //System.err.println("Rel Dir="+__relDir);
System.err.println("User URL="+__userURL); //System.err.println("User URL="+__userURL);
tmpFile=File.createTempFile("test",null).getCanonicalFile(); tmpFile=File.createTempFile("test",null).getCanonicalFile();
tmpFile.deleteOnExit(); tmpFile.deleteOnExit();
@ -146,15 +149,15 @@ public class ResourceTest
data[i++]=new Data(__userURL,EXISTS,DIR); data[i++]=new Data(__userURL,EXISTS,DIR);
data[i++]=new Data(__userDir,EXISTS,DIR); data[i++]=new Data(__userDir,EXISTS,DIR);
data[i++]=new Data(__relDir,EXISTS,DIR); data[i++]=new Data(__relDir,EXISTS,DIR);
data[i++]=new Data(__userURL+"ResourceTest.java",EXISTS,!DIR); data[i++]=new Data(__userURL+"jetty-logging.properties",EXISTS,!DIR);
data[i++]=new Data(__userDir+"ResourceTest.java",EXISTS,!DIR); data[i++]=new Data(__userDir+"jetty-logging.properties",EXISTS,!DIR);
data[i++]=new Data(__relDir+"ResourceTest.java",EXISTS,!DIR); data[i++]=new Data(__relDir+"jetty-logging.properties",EXISTS,!DIR);
data[i++]=new Data(__userURL+"NoName.txt",!EXISTS,!DIR); data[i++]=new Data(__userURL+"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(__userDir+"NoName.txt",!EXISTS,!DIR); data[i++]=new Data(__userDir+"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(__relDir+"NoName.txt",!EXISTS,!DIR); data[i++]=new Data(__relDir+"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(data[rt],"ResourceTest.java",EXISTS,!DIR); data[i++]=new Data(data[rt],"jetty-logging.properties",EXISTS,!DIR);
data[i++]=new Data(data[rt],"/ResourceTest.java",EXISTS,!DIR); data[i++]=new Data(data[rt],"/jetty-logging.properties",EXISTS,!DIR);
data[i++]=new Data(data[rt],"NoName.txt",!EXISTS,!DIR); data[i++]=new Data(data[rt],"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(data[rt],"/NoName.txt",!EXISTS,!DIR); data[i++]=new Data(data[rt],"/NoName.txt",!EXISTS,!DIR);
@ -327,8 +330,7 @@ public class ResourceTest
{ {
String s = "jar:"+__userURL+"TestData/test.zip!/subdir/numbers"; String s = "jar:"+__userURL+"TestData/test.zip!/subdir/numbers";
// TODO move this into src/test/resources!!! ZipFile zf = new ZipFile(MavenTestingUtils.getTestResourceFile("TestData/test.zip"));
ZipFile zf = new ZipFile(MavenTestingUtils.getProjectFile("src/test/java/org/eclipse/jetty/util/resource/TestData/test.zip"));
long last = zf.getEntry("subdir/numbers").getTime(); long last = zf.getEntry("subdir/numbers").getTime();

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Created-By: 1.2.2 (Sun Microsystems Inc.)

View File

@ -0,0 +1 @@
ABCDEFGHIJKLMNOPQRSTUVWXYZ

View File

@ -0,0 +1 @@
1234567890

View File

@ -0,0 +1 @@
ABCDEFGHIJKLMNOPQRSTUVWXYZ

View File

@ -0,0 +1 @@
1234567890

View File

@ -0,0 +1 @@
ABCDEFGHIJKLMNOPQRSTUVWXYZ

View File

@ -0,0 +1 @@
1234567890

View File

@ -60,10 +60,14 @@ public abstract class Descriptor
if (_root == null) if (_root == null)
{ {
//boolean oldValidating = _processor.getParser().getValidating(); try
//_processor.getParser().setValidating(_validating); {
_root = _parser.parse(_xml.getURL().toString()); _root = _parser.parse(_xml.getInputStream());
//_processor.getParser().setValidating(oldValidating); }
finally
{
_xml.release();
}
} }
} }