{"action":"created","issue":{"url":"https://api.github.com/repos/ronmamo/reflections/issues/81","labels_url":"https://api.github.com/repos/ronmamo/reflections/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/ronmamo/reflections/issues/81/comments","events_url":"https://api.github.com/repos/ronmamo/reflections/issues/81/events","html_url":"https://github.com/ronmamo/reflections/issues/81","id":95158893,"number":81,"title":"multithreading issues with 0.9.10","user":{"login":"schabe77","id":13348120,"avatar_url":"https://avatars.githubusercontent.com/u/13348120?v=3","gravatar_id":"","url":"https://api.github.com/users/schabe77","html_url":"https://github.com/schabe77","followers_url":"https://api.github.com/users/schabe77/followers","following_url":"https://api.github.com/users/schabe77/following{/other_user}","gists_url":"https://api.github.com/users/schabe77/gists{/gist_id}","starred_url":"https://api.github.com/users/schabe77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schabe77/subscriptions","organizations_url":"https://api.github.com/users/schabe77/orgs","repos_url":"https://api.github.com/users/schabe77/repos","events_url":"https://api.github.com/users/schabe77/events{/privacy}","received_events_url":"https://api.github.com/users/schabe77/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-15T10:26:31Z","updated_at":"2015-07-16T07:56:07Z","closed_at":null,"body":"Hi!\r\nI'm experiencing multithreading issues with version 0.9.10.\r\n\r\nWith two threads accessing the same jar file i get the following Log Messages:\r\nDEBUG Thread-1 2015-07-15 11:26:33,136 org.reflections.Reflections - going to scan these urls: \r\njar:file:/path/to/jar/myjar.jar!/\r\nDEBUG Thread-2 2015-07-15 11:26:33,138 org.reflections.Reflections - going to scan these urls: ...\r\njar:file:/path/to/jar/myjar.jar!/\r\nINFO 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\r\n\r\nThread-2 crashes with this stack:\r\n\r\njava.lang.IllegalStateException: zip file closed\r\n        at java.util.zip.ZipFile.ensureOpen(ZipFile.java:634)\r\n        at java.util.zip.ZipFile.access$200(ZipFile.java:56)\r\n        at java.util.zip.ZipFile$1.hasMoreElements(ZipFile.java:487)\r\n        at java.util.jar.JarFile$1.hasMoreElements(JarFile.java:241)\r\n        at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:30)\r\n        at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:26)\r\n        at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)\r\n        at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)\r\n        at org.reflections.Reflections.scan(Reflections.java:240)\r\n        at org.reflections.Reflections.scan(Reflections.java:204)\r\n        at org.reflections.Reflections.<init>(Reflections.java:129)\r\n        at org.reflections.Reflections.<init>(Reflections.java:170)\r\n        at org.reflections.Reflections.<init>(Reflections.java:143) \r\n\r\nThe ZipDir seems to be created in DefaultUrlTypes.jarUrl.createDir(URL):\r\n    return new ZipDir(((JarURLConnection) urlConnection).getJarFile()); \r\n\r\nbut sun.net.www.protocol.jar.JarURLConnection.getJarFile() uses (or may use) a cache:\r\n  this.jarFile = factory.get(getJarFileURL(), getUseCaches()); \r\n\r\nIn my case both threads get the same instance of JarFile, and after the first thread has closed the ZipDir (which closes the JarFile) in \r\n  org.reflections.Reflections.scan(URL):260\r\nthe second one gets the IllegalStateException.\r\n\r\nCheers,\r\n\r\nChristian\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ronmamo/reflections/issues/comments/121870178","html_url":"https://github.com/ronmamo/reflections/issues/81#issuecomment-121870178","issue_url":"https://api.github.com/repos/ronmamo/reflections/issues/81","id":121870178,"user":{"login":"schabe77","id":13348120,"avatar_url":"https://avatars.githubusercontent.com/u/13348120?v=3","gravatar_id":"","url":"https://api.github.com/users/schabe77","html_url":"https://github.com/schabe77","followers_url":"https://api.github.com/users/schabe77/followers","following_url":"https://api.github.com/users/schabe77/following{/other_user}","gists_url":"https://api.github.com/users/schabe77/gists{/gist_id}","starred_url":"https://api.github.com/users/schabe77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schabe77/subscriptions","organizations_url":"https://api.github.com/users/schabe77/orgs","repos_url":"https://api.github.com/users/schabe77/repos","events_url":"https://api.github.com/users/schabe77/events{/privacy}","received_events_url":"https://api.github.com/users/schabe77/received_events","type":"User","site_admin":false},"created_at":"2015-07-16T07:56:07Z","updated_at":"2015-07-16T07:56:07Z","body":"A fix could be to disable URLConnection's caching in DefaultUrlTypes.jarUrl.createDir(URL):\r\n\r\n            URLConnection urlConnection = url.openConnection();\r\n            urlConnection.setUseCaches(false);\r\n            if (urlConnection instanceof JarURLConnection) {\r\n                    return new ZipDir(((JarURLConnection) urlConnection).getJarFile());\r\n            }\r\n"}}