activeviam / pivot-spring-boot

Template for running ActivePivot as a Spring Boot application
Apache License 2.0
14 stars 5 forks source link

springboot JAR has error while reading at i18n folder #38

Closed tht-activeviam closed 3 years ago

tht-activeviam commented 4 years ago

This issue only happen at below environment. There is no problem while running in my windows PC

Environment

AWS EC2 t2.2xlarge Ubuntu 18.04.3 LTS openjdk version "11.0.6" 2020-01-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode) Just do maven build from the (https://github.com/activeviam/pivot-spring-boot/tree/5.8-jdk11) to get the jar. No changes required.

Error log

2020-01-21 07:12:03.237 UTC 16992 [main] org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - WARN: Exception encountered during context initialization - cancelling r
efresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initializeCubeFormatters' defined in com.qfs.server.cfg.i18n.impl.LocalI18nConfig: Bean instantiation via f
actory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Void]: Factory method 'initializeCubeFormatters' threw exception; nested exception
 is com.quartetfs.fwk.QuartetRuntimeException: com.quartetfs.fwk.QuartetRuntimeException: Error while reading the resource at jar:file:/home/ubuntu/temp/pivot-springboot.jar!/BOOT-INF/classes!/i18n              
2020-01-21 07:12:03.243 UTC 16998 [main] ActiveViam License - INFO: Resetting ActiveViam Licensing Agent.                                                                                                          
2020-01-21 07:12:03.246 UTC 17001 [main] org.springframework.beans.factory.support.DisposableBeanAdapter - WARN: Destroy method 'stop' on bean with name 'activePivotManager' threw an exception: com.quartetfs.fwk
.AgentException: Agent illegal state transition detected: trying to change from NONE to STOPPED but the authorized previous states are [STARTED, PAUSED].                                                          
2020-01-21 07:12:03.247 UTC 17002 [qfs-discard-on-gc] com.qfs.multiversion.impl.EpochManager - INFO: Thread com.qfs.multiversion.impl.EpochManager$DiscardOnGcTask@4a21cc1 is interrupted!                         
2020-01-21 07:12:03.248 UTC 17003 [main] com.zaxxer.hikari.HikariDataSource - INFO: content - Shutdown initiated...                                                                                                
2020-01-21 07:12:03.250 UTC 17005 [main] com.zaxxer.hikari.HikariDataSource - INFO: content - Shutdown completed.                                                                                                  
2020-01-21 07:12:03.254 UTC 17009 [main] org.apache.catalina.core.StandardService - INFO: Stopping service [Tomcat]                                                                                                
2020-01-21 07:12:03.269 UTC 17024 [main] org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener - INFO:                                                                           

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.                                                                                                  
2020-01-21 07:12:03.272 UTC 17027 [main] org.springframework.boot.SpringApplication - ERROR: Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initial
izeCubeFormatters' defined in com.qfs.server.cfg.i18n.impl.LocalI18nConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to insta
ntiate [java.lang.Void]: Factory method 'initializeCubeFormatters' threw exception; nested exception is com.quartetfs.fwk.QuartetRuntimeException: com.quartetfs.fwk.QuartetRuntimeException: Error while reading t
he resource at jar:file:/home/ubuntu/temp/pivot-springboot.jar!/BOOT-INF/classes!/i18n                                                                                                                             
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)                                                                                                 
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)                                                                               
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)                                                
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)                                                           
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)                                                                  
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)                                                                    
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)                                                                                          
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)                                                                              
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)                                                                                                   
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)                                                                                                     
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)                                                                      
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)                                                                     
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)                                                                                             
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)                                                                    
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743)                                                                                                                          
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390)                                                                                                                   
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)                                                                                                                              
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214)                                                                                                                             
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203)                                                                                                                             
        at com.activeviam.apps.PivotSpringBootApplication.main(PivotSpringBootApplication.java:19)                                                                                                                 
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                          
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)                                                                                                                          
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)                                                                                                                      
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)                                                                                                                                               
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)                                                                                                                          
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)                                                                                                                                       
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)                                                                                                                                       
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)                                                                                                                                   
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Void]: Factory method 'initializeCubeFormatters' threw exception; nested exception is com.quartetfs.fwk.QuartetRu
ntimeException: com.quartetfs.fwk.QuartetRuntimeException: Error while reading the resource at jar:file:/home/ubuntu/temp/pivot-springboot.jar!/BOOT-INF/classes!/i18n                                             
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)                                                                                 
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)                                                                                                 
        ... 27 common frames omitted                                                                                                                                                                               
Caused by: com.quartetfs.fwk.QuartetRuntimeException: com.quartetfs.fwk.QuartetRuntimeException: Error while reading the resource at jar:file:/home/ubuntu/temp/pivot-springboot.jar!/BOOT-INF/classes!/i18n       
        at com.qfs.server.cfg.i18n.impl.I18nConfig.pushTranslations(I18nConfig.java:130)                                                                                                                           
        at com.qfs.server.cfg.i18n.impl.LocalI18nConfig.initializeCubeFormatters(LocalI18nConfig.java:39)                                                                                                          
        at com.qfs.server.cfg.i18n.impl.LocalI18nConfig$$EnhancerBySpringCGLIB$$afbeeb5e.CGLIB$initializeCubeFormatters$0(<generated>)                                                                             
        at com.qfs.server.cfg.i18n.impl.LocalI18nConfig$$EnhancerBySpringCGLIB$$afbeeb5e$$FastClassBySpringCGLIB$$24cf7139.invoke(<generated>)                                                                     
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)                                                                                                                           
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)                                                                  
        at com.qfs.server.cfg.i18n.impl.LocalI18nConfig$$EnhancerBySpringCGLIB$$afbeeb5e.initializeCubeFormatters(<generated>)                                                                                     
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                          
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)                                                                                                                          
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)                                                                                                                      
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)                                                                                                                                               
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)                                                                                 
        ... 28 common frames omitted                                                                                                                                                                               
Caused by: com.quartetfs.fwk.QuartetRuntimeException: Error while reading the resource at jar:file:/home/ubuntu/temp/pivot-springboot.jar!/BOOT-INF/classes!/i18n                                                  
        at com.qfs.util.impl.QfsFiles.walkFileTree(QfsFiles.java:442)                                                                                                                                              
        at com.qfs.server.cfg.i18n.impl.I18nConfig.push(I18nConfig.java:177)                                                                                                                                       
        at com.qfs.server.cfg.i18n.impl.I18nConfig.pushTranslations(I18nConfig.java:128)                                                                                                                           
        ... 39 common frames omitted                                                                                                                                                                               
Caused by: java.io.FileNotFoundException: /home/ubuntu/temp/OOT-INF/classes/i18n/en-US (No such file or directory)                                                                                                 
        at java.base/java.io.FileInputStream.open0(Native Method)                                                                                                                                                  
        at java.base/java.io.FileInputStream.open(Unknown Source)                                                                                                                                                  
        at java.base/java.io.FileInputStream.<init>(Unknown Source)                                                                                                                                                
        at java.base/java.io.FileInputStream.<init>(Unknown Source)                                                                                                                                                
        at java.base/sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)                                                                                                                           
        at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)                                                                                                                    
        at java.base/java.net.URL.openStream(Unknown Source)                                                                                                                                                       
        at com.qfs.util.impl.QfsFiles.getResourceAsStream(QfsFiles.java:210)                                                                                                                                       
        at com.qfs.util.impl.QfsFiles.getResourceAsStream(QfsFiles.java:228)                                                                                                                                       
        at com.qfs.server.cfg.i18n.impl.I18nConfig$1.visitFile(I18nConfig.java:191)                                                                                                                                
        at com.qfs.server.cfg.i18n.impl.I18nConfig$1.visitFile(I18nConfig.java:177)                                                                                                                                
        at java.base/java.nio.file.Files.walkFileTree(Unknown Source)                                                                                                                                              
        at java.base/java.nio.file.Files.walkFileTree(Unknown Source)                                                                                                                                              
        at com.qfs.util.impl.QfsFiles.walkFileTree(QfsFiles.java:440)                                                                                                                                              
tht-activeviam commented 4 years ago

This issue was opened previously at https://github.com/activeviam/pivot-spring-boot/issues/6 It happened again in Ubuntu environment. As a workaround, I used the solution provided by @mfabiani-av at https://github.com/activeviam/pivot-spring-boot/commit/cdd8c548f8bbf8fddb9920d6f6070bc6dcb24915

SBrown52 commented 4 years ago

Did this happen on the latest version, 5.8.6? I wonder if something changed in the core

tht-activeviam commented 4 years ago

Did this happen on the latest version, 5.8.6? I wonder if something changed in the core

Yes, it does. I am using

<activePivotVersion>5.8.6-jdk11</activePivotVersion>
mfabiani-av commented 4 years ago

Have you noticed the path at which the file is being looked up? Caused by: java.io.FileNotFoundException: /home/ubuntu/temp/OOT-INF/classes/i18n/en-US (No such file or directory) It says "OOT-INF" instead of "BOOT-INF" ... don't know if that is just a glitch. Although maybe that is just a fallback path, because the files are actually inside the JAR file.

I don't know what the product center did to fix the issue when reading file from inside the jar, but they do NOT use what we suggested on Confluence. They do something funny with the path, which clearly results in the above wrong path. Don't know how it worked previously but it surely doesn't work now... I guess they don't want to have Spring as a dependency in that library but if it doesn't work....

The problem is in I18nConfig.push() where they create a "SimpleFileVisitor" which takes a path: that path has been previously truncated (e.g. BOOT-INF/classes/i18n/en-US) and then they try to read from it which will then simply put the current path in front of it. The path is actually truncated in QfsFiles.walkFileTree where they check if it is a jar file or a normal file. At some point they create a "jar file system" but they don't used it to read the files....