Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException: zip file closed #279

Open
nurk opened this issue Jan 30, 2020 · 23 comments
Open

java.lang.IllegalStateException: zip file closed #279

nurk opened this issue Jan 30, 2020 · 23 comments

Comments

@nurk
Copy link

nurk commented Jan 30, 2020

When using version 9.12 on kubernetes 1.15 with spring boot 2.2.4 we get following error.
When using version 9.11 we do not have this issue.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [x.x.x.SerializedTypeNameResolver]: Factory method 'serializedTypeNameResolver' threw exception; nested exception is java.lang.IllegalStateException: zip file closed
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
	... 95 common frames omitted
Caused by: java.lang.IllegalStateException: zip file closed
	at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:915) ~[na:na]
	at java.base/java.util.zip.ZipFile.stream(ZipFile.java:647) ~[na:na]
	at java.base/java.util.zip.ZipFile$1.stream(ZipFile.java:1131) ~[na:na]
	at java.base/java.util.jar.JarFile.stream(JarFile.java:534) ~[na:na]
	at org.reflections.vfs.ZipDir.lambda$getFiles$2(ZipDir.java:21) ~[reflections-0.9.12.jar!/:na]
	at org.reflections.Reflections.scan(Reflections.java:260) ~[reflections-0.9.12.jar!/:na]
	at org.reflections.Reflections.scan(Reflections.java:216) ~[reflections-0.9.12.jar!/:na]
	at org.reflections.Reflections.<init>(Reflections.java:137) ~[reflections-0.9.12.jar!/:na]
	at org.reflections.Reflections.<init>(Reflections.java:182) ~[reflections-0.9.12.jar!/:na]
	at org.reflections.Reflections.<init>(Reflections.java:155) ~[reflections-0.9.12.jar!/:na]
	at x.x.x.serializedTypeNameResolver.getTypesForName(SerializedTypeNameResolver.java:44) ~[integration-axondb-11.369.0.jar!/:11.369.0]
	at x.x.x.serializedTypeNameResolver.<init>(GSerializedTypeNameResolver.java:23) ~[integration-axondb-11.369.0.jar!/:11.369.0]
	at x.x.x.serializedTypeNameResolver(AxonServerSharedConfiguration.java:115) ~[integration-axondb-11.369.0.jar!/:11.369.0]

Our config is as follows:

private Map<String, Class<?>> getTypesForName() {
        Reflections reflections = new Reflections("x.x.x");
        return reflections.getTypesAnnotatedWith(JsonTypeInfo.class).stream()
            .map(clazz -> clazz.getAnnotationsByType(JsonSubTypes.class))
            .flatMap(Arrays::stream)
            .flatMap(annotation -> Arrays.stream(annotation.value()))
            .filter(type -> isValidType(type.value()))
            .collect(toMap(JsonSubTypes.Type::name, JsonSubTypes.Type::value, (name1, name2) -> name1));
    }

"edit"
It runs on adoptOpenJdk 11.0.6_10

@PhilippHeuer
Copy link

I just had the same issue with 9.12 in a container with SpringBoot 2.2.4. I'm using OpenJDK11 though, the library only seems to support 8 officially. Running it with 11 on my workstation works though.

@gs80140
Copy link

gs80140 commented Feb 3, 2020

I have the same issue with 9.12 in springboot

@bobaoapae
Copy link

I got the same issue when running a packed jar from spring boot, but starting the same application from the source-code with maven spring plugin, run without any related issue

@youssef3wi
Copy link

take a look at this : sebastianarnold/TeXoo#20 (comment)

trustin added a commit to trustin/armeria that referenced this issue Feb 21, 2020
trustin added a commit to line/armeria that referenced this issue Feb 21, 2020
jrhee17 pushed a commit to jrhee17/armeria that referenced this issue Feb 22, 2020
heowc pushed a commit to heowc/armeria that referenced this issue Feb 25, 2020
@leilove321
Copy link

When using the springboot jar, you can rewrite the org.reflections.vfs.zipfile class and implement it with org.springframework.boot.loader.jar.JarFile.

org.springframework.boot spring-boot-loader

@bessoft
Copy link

bessoft commented May 7, 2020

I have the same issue with 9.12 in springboot

@vlad-poskatcheev-tealium
Copy link

vlad-poskatcheev-tealium commented May 22, 2020

Could this be related to multi threading issue that's been around since 0.9.10 and described in #81? A common "solution" is to downgrade to 0.9.9 until it's fixed. :(

@alla-gofman
Copy link

alla-gofman commented Jun 11, 2020

I have the same issue after upgrading to reflections 9.12.
I use spring framework version 5.2.1.RELEASE

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.bmc.cm.command.cm_actuators.ClassFinder]: Factory method 'getClassFinder' threw exception; nested exception is java.lang.IllegalStateException: zip file closed at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:640) ... 81 more Caused by: java.lang.IllegalStateException: zip file closed at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:915) at java.base/java.util.zip.ZipFile.stream(ZipFile.java:647) at java.base/java.util.zip.ZipFile$1.stream(ZipFile.java:1131) at java.base/java.util.jar.JarFile.stream(JarFile.java:534) at org.reflections.vfs.ZipDir.lambda$getFiles$2(ZipDir.java:21) at org.reflections.Reflections.scan(Reflections.java:260) at org.reflections.Reflections.scan(Reflections.java:216) at org.reflections.Reflections.<init>(Reflections.java:137) at org.reflections.Reflections.<init>(Reflections.java:182) at org.reflections.Reflections.<init>(Reflections.java:155) ... at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) at com.bmc.cm.aft.cfg.AftConfiguration$$EnhancerBySpringCGLIB$$3eca469e.getClassFinder(<generated>) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)

@yotamshtosselfg
Copy link

#me_too --> downgraded to 0.9.11 as suggested.

@nik-sta
Copy link

nik-sta commented Aug 14, 2020

Facing the same issue ... any updates?

fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this issue Sep 19, 2020
@idkw
Copy link

idkw commented Oct 20, 2020

This is still an issue, I also had to downgrade to 0.9.11, is there something we can do to help figure this out ?

@bosco688
Copy link

Same issue since Spring Boot upgrade from 2.3.3 to 2.3.4 (spring-boot-starter-parent)

@planetf1
Copy link

planetf1 commented Nov 3, 2020

We've seen the same with egeria (link above) which affects both 2.3.4 and 2.3.5 of spring boot. 2.3.3 is working fine.

We do have a dependency (maven build) on reflections 0.9.12 also used elsewhere.

@nachomezzadra
Copy link

This seems to have been fixed now in Spring boot 2.3.6.RELEASE

  • "java.lang.IllegalStateException: zip file closed" when call JarFileWrapper.stream() of spring-boot-loader #23821

https://github.com/spring-projects/spring-boot/releases/tag/v2.3.6.RELEASE

@bmaehr
Copy link

bmaehr commented Dec 7, 2020

This seems to have been fixed now in Spring boot 2.3.6.RELEASE

  • "java.lang.IllegalStateException: zip file closed" when call JarFileWrapper.stream() of spring-boot-loader #23821

https://github.com/spring-projects/spring-boot/releases/tag/v2.3.6.RELEASE

As far as I understood spring fixed a similar problem, but not the same. At least I still have the problem with spring-boot 2.4.0 and reflections 0.9.12. Downgrading to 0.9.11 solves it.

@tandr
Copy link

tandr commented Jan 30, 2021

0.9.11 has the same error popping up for us randomly (we are not using spring), with exactly same message. Could it be that there is something unfortunate in openjdk 11? We are mixing things built with java 11 and java 8, don't know if this is important.

@lucasvc
Copy link

lucasvc commented Mar 25, 2021

When using the springboot jar, you can rewrite the org.reflections.vfs.zipfile class and implement it with org.springframework.boot.loader.jar.JarFile.

org.springframework.boot spring-boot-loader

I'm trying (after some time digging) but I'm still getting same issue,

Vfs.addDefaultURLTypes(new Vfs.UrlType()
{
    @Override
    public boolean matches(final URL url) throws Exception
    {
        return url.getProtocol().equals("jar") && isInsideBootInf(url);
    }

    private boolean isInsideBootInf(final URL url)
    {
        return url.toExternalForm().matches("^.*\\.jar\\!\\/BOOT-INF\\/lib\\/my-fancy-lib(?:-\\d+\\.\\d+\\.\\d+)?\\.jar\\!\\/$");
    }

    @Override
    public Vfs.Dir createDir(final URL url) throws Exception
    {
        return new ZipDir(new org.springframework.boot.loader.jar.JarFile(Vfs.getFile(url)));
    }
});
final Reflections reflections = new Reflections(baseClassPackage);

@idkw
Copy link

idkw commented Jun 23, 2021

Can a 0.9.13 patch version be released to fix this issue ?
Do you need help to make this happen ? What can we do to help ?

@austinarbor
Copy link

austinarbor commented Oct 13, 2021

Does this issue still persist in latest 0.10.x releases?

@ronmamo
Copy link
Owner

ronmamo commented Oct 27, 2021

as @nachomezzadra mentioned

This seems to have been fixed now in Spring boot 2.3.6.RELEASE

  • "java.lang.IllegalStateException: zip file closed" when call JarFileWrapper.stream() of spring-boot-loader #23821

https://github.com/spring-projects/spring-boot/releases/tag/v2.3.6.RELEASE

not sure if it worth a workaround (avoid jarFile.stream() introduced in 937c8f3 ZipDir#getFiles) even though it was fixed later in springboot, or else

@austinarbor
Copy link

Oh ok, I wasn't sure if it was fixed because of these comments

#279 (comment)

#279 (comment)

I am on Spring 2.5.x so I will give latest version a try

@sureshkumarchoudhary
Copy link

sureshkumarchoudhary commented May 27, 2022

downgraded to 0.9.11 and worked for me. For me issue was only when i was running as docker container.

@vadeg
Copy link

vadeg commented Oct 18, 2022

I have checked different versions of Spring and I can confirm what @bmaehr already mentioned. The library throws this exception when it is used with spring-boot of version 2.3.5 or earlier. Switching to 2.3.6 solves the issue.
With the latest spring-boot version 2.7.4 it also works.

Spring framework ticket related to this issue: spring-projects/spring-boot#23821

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests