347130 Empty getResourcePaths due to ZipFileClosedException

This commit is contained in:
Jan Bartel 2012-07-31 18:31:53 +10:00
parent c7c4c6e13b
commit 4d889de159
1 changed files with 89 additions and 55 deletions

View File

@ -19,6 +19,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -108,7 +109,7 @@ class JarFileResource extends JarResource
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Returns true if the respresenetd resource exists. * Returns true if the represented resource exists.
*/ */
@Override @Override
public boolean exists() public boolean exists()
@ -240,13 +241,43 @@ class JarFileResource extends JarResource
@Override @Override
public synchronized String[] list() public synchronized String[] list()
{ {
if (isDirectory() && _list==null) if (isDirectory() && _list==null)
{ {
ArrayList list = new ArrayList(32); List<String> list = null;
try
{
list = listEntries();
}
catch (Exception e)
{
//Sun's JarURLConnection impl for jar: protocol will close a JarFile in its connect() method if
//useCaches == false (eg someone called URLConnection with defaultUseCaches==true).
//As their sun.net.www.protocol.jar package caches JarFiles and/or connections, we can wind up in
//the situation where the JarFile we have remembered in our _jarFile member has actually been closed
//by other code.
//So, do one retry to drop a connection and get a fresh JarFile
LOG.warn("Retrying list:"+e);
LOG.debug(e);
release();
list = listEntries();
}
if (list != null)
{
_list=new String[list.size()];
list.toArray(_list);
}
}
return _list;
}
/* ------------------------------------------------------------ */
private List<String> listEntries ()
{
checkConnection(); checkConnection();
ArrayList<String> list = new ArrayList<String>(32);
JarFile jarFile=_jarFile; JarFile jarFile=_jarFile;
if(jarFile==null) if(jarFile==null)
{ {
@ -258,6 +289,8 @@ class JarFileResource extends JarResource
} }
catch(Exception e) catch(Exception e)
{ {
e.printStackTrace();
LOG.ignore(e); LOG.ignore(e);
} }
} }
@ -295,12 +328,13 @@ class JarFileResource extends JarResource
list.add(listName); list.add(listName);
} }
_list=new String[list.size()]; return list;
list.toArray(_list);
}
return _list;
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Return the length of the resource * Return the length of the resource