Skip to content

multithreading issues with 0.9.10 #81

@schabe77

Description

@schabe77

Hi!
I'm experiencing multithreading issues with version 0.9.10.

With two threads accessing the same jar file i get the following Log Messages:
DEBUG Thread-1 2015-07-15 11:26:33,136 org.reflections.Reflections - going to scan these urls:
jar:file:/path/to/jar/myjar.jar!/
DEBUG Thread-2 2015-07-15 11:26:33,138 org.reflections.Reflections - going to scan these urls: ...
jar:file:/path/to/jar/myjar.jar!/
INFO Thread-1 2015-07-15 11:26:33,289 org.reflections.Reflections - Reflections took 153 ms to scan 3 urls, producing 207 keys and 529 values

Thread-2 crashes with this stack:

java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:634)
at java.util.zip.ZipFile.access$200(ZipFile.java:56)
at java.util.zip.ZipFile$1.hasMoreElements(ZipFile.java:487)
at java.util.jar.JarFile$1.hasMoreElements(JarFile.java:241)
at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:30)
at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:26)
at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
at org.reflections.Reflections.scan(Reflections.java:240)
at org.reflections.Reflections.scan(Reflections.java:204)
at org.reflections.Reflections.(Reflections.java:129)
at org.reflections.Reflections.(Reflections.java:170)
at org.reflections.Reflections.(Reflections.java:143)

The ZipDir seems to be created in DefaultUrlTypes.jarUrl.createDir(URL):
return new ZipDir(((JarURLConnection) urlConnection).getJarFile());

but sun.net.www.protocol.jar.JarURLConnection.getJarFile() uses (or may use) a cache:
this.jarFile = factory.get(getJarFileURL(), getUseCaches());

In my case both threads get the same instance of JarFile, and after the first thread has closed the ZipDir (which closes the JarFile) in
org.reflections.Reflections.scan(URL):260
the second one gets the IllegalStateException.

Cheers,

Christian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions