内联类在openJdk上生成奇怪的名称

时间:2018-11-01 09:12:59

标签: java spring-boot kotlin inline

嘿, 我正在用Kotlin构建Spring Boot应用程序,并想使用内联类。我制作了一个Spring数据存储库,该存储库的方法如下: fun getBy(name: GameName)  其中GameName是内联类 inline class GameName(val value: String)

一切都在本地运行,我正在运行jdk 1.8.0_181-b13。但是,当我将其部署到Google Cloud时,Spring Boot应用程序无法启动。 Google云似乎正在运行openjdk 1.8.0_181。

当我在本地反编译代码时,它看起来像这样: public GameConfigurationEntity getBy_00UsoVY/* $FF was: getBy-00UsoVY*/(@NotNull String gameName, @NotNull UUID id) { ... }

但是在Google Cloud上,出现以下错误: Caused by: java.lang.ClassFormatError: Illegal method name "getByName-MZoZWhM"

因此,在本地似乎它使用_,而在Google云上它使用-,并且-在方法名称中不是有效的字符。

还有其他人吗?

完整的堆栈跟踪: [INFO] GCLOUD: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gameConfigurationService' defined in URL [jar:file:/app.jar!/BOOT-INF/classes!/com/hexigames/configurationservice/domain/game/GameConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.hexigames.configurationservice.domain.game.GameConfigurationService: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:581) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.6.RELEASE.jar!/:2.0.6.RELEASE] [INFO] GCLOUD: at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.6.RELEASE.jar!/:2.0.6.RELEASE] [INFO] GCLOUD: at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.6.RELEASE.jar!/:2.0.6.RELEASE] [INFO] GCLOUD: at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.6.RELEASE.jar!/:2.0.6.RELEASE] [INFO] GCLOUD: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.6.RELEASE.jar!/:2.0.6.RELEASE] [INFO] GCLOUD: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.6.RELEASE.jar!/:2.0.6.RELEASE] [INFO] GCLOUD: at com.hexigames.configurationservice.ConfigurationServiceApplicationKt.main(ConfigurationServiceApplication.kt:12) [classes!/:0.0.1-SNAPSHOT] [INFO] GCLOUD: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181] [INFO] GCLOUD: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181] [INFO] GCLOUD: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181] [INFO] GCLOUD: at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181] [INFO] GCLOUD: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [app.jar:0.0.1-SNAPSHOT] [INFO] GCLOUD: at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [app.jar:0.0.1-SNAPSHOT] [INFO] GCLOUD: at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [app.jar:0.0.1-SNAPSHOT] [INFO] GCLOUD: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [app.jar:0.0.1-SNAPSHOT] [INFO] GCLOUD: Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.hexigames.configurationservice.domain.game.GameConfigurationService: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null [INFO] GCLOUD: at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:208) ~[spring-aop-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:473) ~[spring-aop-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:355) ~[spring-aop-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:304) ~[spring-aop-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: ... 23 common frames omitted [INFO] GCLOUD: Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null [INFO] GCLOUD: at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:345) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:492) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_181] [INFO] GCLOUD: at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:337) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:58) ~[spring-aop-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:205) ~[spring-aop-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: ... 30 common frames omitted [INFO] GCLOUD: Caused by: java.lang.reflect.InvocationTargetException: null [INFO] GCLOUD: at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source) ~[na:na] [INFO] GCLOUD: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181] [INFO] GCLOUD: at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181] [INFO] GCLOUD: at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:459) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE] [INFO] GCLOUD: ... 43 common frames omitted [INFO] GCLOUD: Caused by: java.lang.ClassFormatError: Illegal method name "createConfiguration-tQynZQ0" in class com/hexigames/configurationservice/domain/game/GameConfigurationService$$EnhancerBySpringCGLIB$$76757398 [INFO] GCLOUD: at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_181] [INFO] GCLOUD: at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0_181] [INFO] GCLOUD: ... 48 common frames omitted [INFO] GCLOUD: [INFO] GCLOUD: I1101 09:02:28.364653 25 jvmti_agent.cc:225] Java VM termination [INFO] GCLOUD: I1101 09:02:28.377487 36 jvmti_agent_thread.cc:103] Agent thread exited: CloudDebugger_main_worker_thread [INFO] GCLOUD: I1101 09:02:28.398113 25 worker.cc:116] Debugger threads terminated [INFO] GCLOUD: I1101 09:02:28.405902 25 jvmti_agent.cc:239] JvmtiAgent::JvmtiOnVMDeath cleanup time: 44024 microseconds

2 个答案:

答案 0 :(得分:1)

关键点在堆栈跟踪的底部:

org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) ~[spring-core-5.0.10.RELEASE.jar!/:5.0.10.RELEASE]
[INFO] GCLOUD:  ... 43 common frames omitted
[INFO] GCLOUD: Caused by: java.lang.ClassFormatError: Illegal method name "createConfiguration-tQynZQ0" in class com/hexigames/configurationservice/domain/game/GameConfigurationService$$EnhancerBySpringCGLIB$$76757398
[INFO] GCLOUD:  at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_181]
[INFO] GCLOUD:  at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0_181]

换句话说,Spring使用定制的类加载器按需生成一个类。此类使用带有-的方法名称。类加载器中的defineClass1方法使它窒息。由于类加载器用于加载任何类,因此我唯一的假设是,谷歌云以某种方式使用了经过调整的类加载器。由于类加载器对安全性高度敏感,因此这是有道理的,但显然您的Kotlin代码对安全性不敏感。

根据JVM规范,在JVM级别https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2.2的方法名称中,-字符不是非法字符。因此,这似乎是Google云平台中的错误。顺便说一句。该字符在Java中是非法的,但JVM宽容得多。

答案 1 :(得分:-1)

发生这种情况是由于kotlin编译器完成了名称处理。不能从Java调用接受内联类的函数。 (Official docs