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

ClosedFileSystemException when including resources into a native compile #29452

Closed
Artur- opened this issue Nov 9, 2022 · 5 comments
Closed
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue theme: aot An issue related to Ahead-of-time processing type: bug A general bug

Comments

@Artur-
Copy link

Artur- commented Nov 9, 2022

When trying out https://github.com/vaadin/hilla and https://github.com/vaadin/flow together with the native support in Spring Boot 3, I ran into an issue on startup:

java.lang.RuntimeException: Unable to initialize com.vaadin.flow.spring.VaadinServletContextInitializer$ErrorParameterServletContextListener
	at com.vaadin.flow.spring.VaadinServletContextInitializer$FailFastServletContextListener.contextInitialized(VaadinServletContextInitializer.java:191) ~[hilla-native:na]
	at com.vaadin.flow.spring.VaadinServletContextInitializer$CompositeServletContextListener.lambda$contextInitialized$0(VaadinServletContextInitializer.java:213) ~[na:na]
	at java.base@19.0.1/java.util.ArrayList.forEach(ArrayList.java:1511) ~[hilla-native:na]
	at com.vaadin.flow.spring.VaadinServletContextInitializer$CompositeServletContextListener.contextInitialized(VaadinServletContextInitializer.java:213) ~[na:na]
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4716) ~[hilla-native:10.0.27]
...
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/com/vaadin/flow/router/AfterNavigationEvent.class]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:462) ~[hilla-native:6.0.0-RC2]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316) ~[hilla-native:6.0.0-RC2]
	at java.base@19.0.1/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[na:na]
...
Caused by: java.nio.file.ClosedFileSystemException: null
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem.ensureOpen(NativeImageResourceFileSystem.java:142) ~[na:na]
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem.newInputStream(NativeImageResourceFileSystem.java:742) ~[na:na]
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourcePath.newInputStream(NativeImageResourcePath.java:851) ~[na:na]
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystemProvider.newInputStream(NativeImageResourceFileSystemProvider.java:214) ~[hilla-native:na]
	at java.base@19.0.1/java.nio.file.Files.newInputStream(Files.java:160) ~[na:na]
	at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:192) ~[na:na]
	at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:54) ~[na:na]
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:48) ~[na:na]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[hilla-native:6.0.0-RC2]
	at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:122) ~[na:na]

The code in VaadinServletContextInitializer.java:191 is

} catch (Exception e) {
...
                    throw new RuntimeException(
                            "Unable to initialize " + this.getClass().getName(),
                            e);

and the exception it catches is

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/com/vaadin/flow/router/AfterNavigationEvent.class]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:462)
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316)
	at java.base@19.0.1/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base@19.0.1/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1715)
	at java.base@19.0.1/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base@19.0.1/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base@19.0.1/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base@19.0.1/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base@19.0.1/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at com.vaadin.flow.spring.VaadinServletContextInitializer$ErrorParameterServletContextListener.failFastContextInitialized(VaadinServletContextInitializer.java:369)
...
Caused by: java.nio.file.ClosedFileSystemException
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem.ensureOpen(NativeImageResourceFileSystem.java:142)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem.newInputStream(NativeImageResourceFileSystem.java:742)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourcePath.newInputStream(NativeImageResourcePath.java:851)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystemProvider.newInputStream(NativeImageResourceFileSystemProvider.java:214)
	at java.base@19.0.1/java.nio.file.Files.newInputStream(Files.java:160)
	at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:192)
	at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:54)

The flow-server.jar has resources in com/vaadin/flow/component, com/vaadin/flow/router and com/vaadin/flow/server and to make testing easier I included

hints.resources().registerPattern("com/vaadin/flow/*");

in a RuntimeHintsRegistrar and this seems to trigger the problem. If I restrict the pattern to com/vaadin/flow/server/* then I do not see the problem. Probably because the mentioned class com/vaadin/flow/router/AfterNavigationEvent.class is not included as a resource

Example project at https://github.com/Artur-/hilla-native/tree/closedfilesystemexception

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 9, 2022
@snicoll snicoll transferred this issue from spring-projects/spring-boot Nov 9, 2022
@snicoll
Copy link
Member

snicoll commented Nov 9, 2022

@Artur- thanks for the report, I believe this could have been a duplicate of #29397 but you're already using the version with that fix. We'll have another look.

@Artur-
Copy link
Author

Artur- commented Nov 9, 2022

I believe I am using Spring 6.0.0-RC2 and the fix is marked for 6.0.0-RC3?

@snicoll
Copy link
Member

snicoll commented Nov 9, 2022

Indeed, sorry. It might be a duplicate after all. Can you please try with either 3.0.0-SNAPSHOT or by setting spring-framework.version to 6.0.0-RC3?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Nov 9, 2022
@Artur-
Copy link
Author

Artur- commented Nov 9, 2022

Using <spring-framework.version>6.0.0-RC3</spring-framework.version> indeed seems to solve this problem, thanks.
I do run into other errors about missing classes but those are probably my fault

@Artur- Artur- closed this as completed Nov 9, 2022
@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2022
@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 9, 2022
@snicoll
Copy link
Member

snicoll commented Nov 9, 2022

Thanks for checking and reporting back.

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug labels Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants