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

Runnable jar fails for 5.2.0 #12589

Closed
sbortman opened this issue Jun 24, 2022 · 13 comments
Closed

Runnable jar fails for 5.2.0 #12589

sbortman opened this issue Jun 24, 2022 · 13 comments
Assignees
Milestone

Comments

@sbortman
Copy link

sbortman commented Jun 24, 2022

Expected Behavior

App should start normally

Actual Behaviour

Get a stack trace, app doesn't start.

ava.nio.file.FileSystemAlreadyExistsException: null
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
	at java.base/java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:678)
	at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:722)
	at io.micronaut.core.io.service.SoftServiceLoader$DefaultServiceCollector.collect(SoftServiceLoader.java:536)
	at io.micronaut.core.io.service.SoftServiceLoader.collectDynamicServices(SoftServiceLoader.java:199)
	at io.micronaut.core.io.service.SoftServiceLoader.collectAll(SoftServiceLoader.java:175)
	at io.micronaut.context.DefaultBeanContext.resolveBeanDefinitionReferences(DefaultBeanContext.java:1730)
	at io.micronaut.context.DefaultApplicationContext.isBootstrapPropertySourceLocatorPresent(DefaultApplicationContext.java:153)
	at io.micronaut.context.DefaultApplicationContext.isBootstrapEnabled(DefaultApplicationContext.java:149)
	at io.micronaut.context.DefaultApplicationContext.createEnvironment(DefaultApplicationContext.java:137)
	at io.micronaut.context.DefaultApplicationContext.getEnvironment(DefaultApplicationContext.java:181)
	at grails.boot.GrailsApp.createApplicationContext(GrailsApp.groovy:181)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
	at foo.app.Application.main(Application.groovy:11)
	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.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.nio.file.FileSystemAlreadyExistsException: null
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:102)
	at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:337)
	at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:286)
	at io.micronaut.core.io.IOUtils.eachFile(IOUtils.java:88)
	at io.micronaut.core.io.service.SoftServiceLoader.computeServiceTypeNames(SoftServiceLoader.java:277)
	at io.micronaut.core.io.service.SoftServiceLoader.access$1100(SoftServiceLoader.java:68)
	at io.micronaut.core.io.service.SoftServiceLoader$MicronautMetaServicesLoader.compute(SoftServiceLoader.java:565)
	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:189)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Steps To Reproduce

  1. Install SDKMan
  2. sdk install grails 5.2.0
  3. grails create-app foobar
  4. cd foobar
  5. ./gradlew clean bootJar
  6. java -jar build/libs/foobar-0.1.jar

Environment Information

MacOSX 12.4

sdk current

Using:

ant: 1.10.12
gradle: 7.4.2
grails: 5.2.0
groovy: 3.0.11
java: 11.0.15.fx-zulu
kotlin: 1.7.0
maven: 3.8.6
micronaut: 3.5.2
springboot: 2.7.1
tomcat: 10.0.22
SBortman-MacBook-Pro /tmp/foo-app $

Example Application

No response

Version

5.2.0

@puneetbehl puneetbehl self-assigned this Jun 24, 2022
@puneetbehl puneetbehl added this to the 5.2.1 milestone Jun 24, 2022
@spmcewen
Copy link

spmcewen commented Jun 24, 2022

I ran into this problem as well when launching the Spring Boot jar on macOS. Launching the jar in a Linux docker container fails with:

io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).

which sounds similar to this Micronaut issue: issue with Micronaut: micronaut-projects/micronaut-core#7144. The workarounds in that thread did not work for me.

@pangeaos
Copy link

I ran with the same problem.

@codeconsole
Copy link
Contributor

codeconsole commented Jun 26, 2022

Example App:

sdk use java 22.1.0.r11-grl 
git clone https://github.com/codeconsole/website
cd website
./gradlew bootJar

% java -jar build/libs/website-0.1.jar 
2022-06-26 15:26:14.607 ERROR --- [           main] o.s.boot.SpringApplication               : Application run failed

java.nio.file.ClosedFileSystemException: null
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
	at java.base/java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:678)
	at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:722)
	at io.micronaut.core.io.service.SoftServiceLoader$DefaultServiceCollector.collect(SoftServiceLoader.java:536)
	at io.micronaut.core.io.service.SoftServiceLoader.collectDynamicServices(SoftServiceLoader.java:199)
	at io.micronaut.core.io.service.SoftServiceLoader.collectAll(SoftServiceLoader.java:175)
	at io.micronaut.context.DefaultBeanContext.resolveBeanDefinitionReferences(DefaultBeanContext.java:1730)
	at io.micronaut.context.DefaultApplicationContext.isBootstrapPropertySourceLocatorPresent(DefaultApplicationContext.java:153)
	at io.micronaut.context.DefaultApplicationContext.isBootstrapEnabled(DefaultApplicationContext.java:149)
	at io.micronaut.context.DefaultApplicationContext.createEnvironment(DefaultApplicationContext.java:137)
	at io.micronaut.context.DefaultApplicationContext.getEnvironment(DefaultApplicationContext.java:181)
	at grails.boot.GrailsApp.createApplicationContext(GrailsApp.groovy:181)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
	at grails.boot.GrailsApp.run(GrailsApp.groovy:99)

@codeconsole
Copy link
Contributor

codeconsole commented Jun 26, 2022

https://github.com/grails/grails-core/blob/5.2.x/grails-core/src/main/groovy/grails/boot/GrailsApp.groovy#L181-L183

micronautContext
        .environment
        .addPropertySource("grails-config", [(MicronautBeanFactoryConfiguration.PREFIX + ".bean-excludes"): (Object)beanExcludes])

@jnunderwood
Copy link

I get the following exception when running in a Linux Docker container using JDK 11:

java.nio.file.ClosedFileSystemException: null
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
        at java.base/java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:678)
        at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:722)
        at io.micronaut.core.io.service.SoftServiceLoader$DefaultServiceCollector.collect(SoftServiceLoader.java:536)
        at io.micronaut.core.io.service.SoftServiceLoader.collectDynamicServices(SoftServiceLoader.java:199)
        at io.micronaut.core.io.service.SoftServiceLoader.collectAll(SoftServiceLoader.java:175)
        at io.micronaut.context.DefaultBeanContext.resolveBeanDefinitionReferences(DefaultBeanContext.java:1730)
        at io.micronaut.context.DefaultApplicationContext.isBootstrapPropertySourceLocatorPresent(DefaultApplicationContext.java:153)
        at io.micronaut.context.DefaultApplicationContext.isBootstrapEnabled(DefaultApplicationContext.java:149)
        at io.micronaut.context.DefaultApplicationContext.createEnvironment(DefaultApplicationContext.java:137)
        at io.micronaut.context.DefaultApplicationContext.getEnvironment(DefaultApplicationContext.java:181)
        at grails.boot.GrailsApp.createApplicationContext(GrailsApp.groovy:181)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
        at grails.boot.GrailsApp$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
        at cleanhands.Application.main(Application.groovy:14)
        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.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: java.nio.file.ClosedFileSystemException: null
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.ensureOpen(ZipFileSystem.java:1193)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.getFileAttributes(ZipFileSystem.java:348)
        at jdk.zipfs/jdk.nio.zipfs.ZipPath.getAttributes(ZipPath.java:740)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.readAttributes(ZipFileSystemProvider.java:292)
        at java.base/java.nio.file.Files.readAttributes(Files.java:1764)
        at java.base/java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:219)
        at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:276)
        at java.base/java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:322)
        at java.base/java.nio.file.FileTreeIterator.<init>(FileTreeIterator.java:71)
        at java.base/java.nio.file.Files.walk(Files.java:3825)
        at io.micronaut.core.io.IOUtils.eachFile(IOUtils.java:102)
        at io.micronaut.core.io.service.SoftServiceLoader.computeServiceTypeNames(SoftServiceLoader.java:277)
        at io.micronaut.core.io.service.SoftServiceLoader.access$1100(SoftServiceLoader.java:68)
        at io.micronaut.core.io.service.SoftServiceLoader$MicronautMetaServicesLoader.compute(SoftServiceLoader.java:565)
        at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:189)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

puneetbehl added a commit to micronaut-projects/micronaut-core that referenced this issue Jun 28, 2022
Refactor code around file system to synchronously access file system when using JAR.

Fixes grails/grails-core#12589
@puneetbehl
Copy link
Contributor

I think I have fixed one part of the problem where you won't see exceptions such as java.nio.file.FileSystemAlreadyExistsException. However, I am still debugging the another error which is:

io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
        at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2784)
        at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1596)
        at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:865)
        at io.micronaut.context.BeanLocator.getBean(BeanLocator.java:94)
        at io.micronaut.context.DefaultBeanContext.publishEvent(DefaultBeanContext.java:1682)
        at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:354)
        at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:190)
        at grails.boot.GrailsApp.createApplicationContext(GrailsApp.groovy:184)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
        at foobar.Application.main(Application.groovy:11)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)

It looks like io.micronaut.core.io.service.SoftServiceLoader is unable to pick BeanDefinitionReference from BOOT-INF/lib/micronaut-inject-3.5.1.jar!/META-INF/micronaut/io.micronaut.inject.BeanDefinitionReference which results in the above error.

@codeconsole
Copy link
Contributor

@puneetbehl Does that have anything to do with the actual build process?

micronaut-projects/micronaut-gradle-plugin#406

I think I have fixed one part of the problem where you won't see exceptions such as java.nio.file.FileSystemAlreadyExistsException. However, I am still debugging the another error which is:

io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
        at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2784)

It looks like io.micronaut.core.io.service.SoftServiceLoader is unable to pick BeanDefinitionReference from BOOT-INF/lib/micronaut-inject-3.5.1.jar!/META-INF/micronaut/io.micronaut.inject.BeanDefinitionReference which results in the above error.

@puneetbehl
Copy link
Contributor

I don't think it has anything to do with it. Basically the problem is with Micronaut 3.5 where it does not support reading BeanDefinitionReference from nested JAR. For example, the path is jar:file:/Users/pbehl/Downloads/foobar/build/libs/foobar-0.1.jar!/BOOT-INF/lib/micronaut-inject-3.5.3-SNAPSHOT.jar!/META-INF/micronaut/io.micronaut.inject.BeanDefinitionReference.

I am working on a Pull Request to support the same which I believe should fix the problem.

@codeconsole
Copy link
Contributor

@puneetbehl thanks for the update!

@codeconsole
Copy link
Contributor

@puneetbehl it sounds like they need you to provide them a way to replicate the issue

@hayeskl
Copy link

hayeskl commented Jul 14, 2022

This is still broken when the injected bean references are stored in /BOOT-INF/classes i.e.

jar:file:/Users/khayes/foobar/build/libs/foobar-0.1.jar!/BOOT-INF/classes!/META-INF/micronaut/io.micronaut.inject.BeanDefinitionReference

@jnunderwood
Copy link

For my projects at least, v5.2.1 fixes this issue. Thanks.

@puneetbehl
Copy link
Contributor

This should be resolved with 5.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment