Reflections - Java 8 - invalid constant type
来源:互联网 发布:2016年餐饮行业数据 编辑:程序博客网 时间:2024/06/08 07:47
异常说明
使用Reflections扫描的时候出现could not create class file from
, 原因是invalid constant type: 18
异常堆栈:
org.reflections.ReflectionsException: could not create class file from EmployeeDao.class at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:102) at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:24) at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:30) at org.reflections.Reflections.scan(Reflections.java:250) at org.reflections.Reflections.scan(Reflections.java:204) at org.reflections.Reflections.<init>(Reflections.java:129) at org.reflections.Reflections.<init>(Reflections.java:170) at org.reflections.Reflections.<init>(Reflections.java:143) at com.mljr.fenqi.crm.core.cache.RedisCacheConfig.parseRedisCacheTTL(RedisCacheConfig.java:63) at com.mljr.fenqi.crm.core.cache.RedisCacheConfig.onApplicationEvent(RedisCacheConfig.java:40) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:855) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)Caused by: java.io.IOException: invalid constant type: 18 at javassist.bytecode.ConstPool.readOne(ConstPool.java:1113) at javassist.bytecode.ConstPool.read(ConstPool.java:1056) at javassist.bytecode.ConstPool.<init>(ConstPool.java:150) at javassist.bytecode.ClassFile.read(ClassFile.java:765) at javassist.bytecode.ClassFile.<init>(ClassFile.java:109) at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:100) ... 45 more
看了一篇文章说是 代码中是用的解析字节码的库 既不兼容jdk1.8 甚至可能都不兼容jdk1.7, 如果编译器没问题,那问题就在这个解析字节码的库
If you look at this table, you’ll see that “constant type: 18” refers to the CONSTANT_InvokeDynamic attribute whose tag value is 18.
So you are using a library which has a class parser which is not Java 8 compatible. Actually, this class parser even isn’t Java 7 compatible as this constant value is specified since Java 7. It just got away with that as ordinary Java code doesn’t use this feature in Java 7. But when interacting with code produced by different programming languages for the JVM, it could even fail with Java 7.
There’s an item in the bug tracker of Reflections describing your problem. At the bottom, you will find the notice:
解决方案
由于Reflections解析字节码使用了javassist库, 换个版本试试,解决问题的版本 javassist-3.18.2-GA
,如果其他的库有依赖javasist的,需要统一版本,就需要exclusion
pom.xml
<dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.9.10</version> <exclusions> <exclusion> <groupId>javassist</groupId> <artifactId>javassist</artifactId> </exclusion> </exclusions></dependency><dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.18.2-GA</version></dependency>
扫描代码:
Map<String, Long> map = new HashMap<>();ConfigurationBuilder builder = new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().includePackage("com.mljr.fenqi.crm")) .addUrls(ClasspathHelper.forPackage("com.mljr")) .setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner(), new TypeElementsScanner(), new SubTypesScanner());Reflections reflections = new Reflections(builder);Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(RedisCache.class);for (Class<?> serviceClass : annotated) { RedisCache typeRedisCache = serviceClass.getAnnotation(RedisCache.class); if (typeRedisCache != null ) { for (String name : typeRedisCache.cacheNames()) { map.put(name, typeRedisCache.expire()); } }}Set<Method> annotatedMethod = reflections.getMethodsAnnotatedWith(RedisCache.class);for (Method method : annotatedMethod) { RedisCache methodRedisCache = method.getAnnotation(RedisCache.class); if (methodRedisCache != null ) { for (String name : methodRedisCache.cacheNames()) { map.put(name, methodRedisCache.expire()); } }}
REF
- http://stackoverflow.com/questions/30313255/reflections-java-8-invalid-constant-type
- https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.10
- http://blog.csdn.net/zxhoo/article/details/38387141
- Reflections - Java 8 - invalid constant type
- java.io.IOException: invalid constant type: 15
- java.io.IOException: invalid constant type: 18
- 在使用java 8 lamda时,报错解决:java.io.IOException: invalid constant type: 18
- java.lang.RuntimeException: java.io.IOException: invalid constant type: 15
- java.lang.RuntimeException: java.io.IOException: invalid constant type: 15
- alibaba.dubbo-java.io.IOException: invalid constant type: 15
- 异常解决java.io.IOException: invalid constant type: 15
- invalid constant type: 15问题解决
- invalid constant type: 15 错误解决
- invalid constant type: 15 错误解决
- 启动dubbo报错解决:java.lang.RuntimeException: java.io.IOException: invalid constant type: 15
- Play framework1.2.x java.io.IOException: invalid constant type: 18
- 调用dubbo服务提示:java.io.IOException: invalid constant type: 18
- 升级jdk8后系统报错解决:java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
- 升级jdk8后系统报错解决:java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
- 大数据开发中遇到的错误 java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
- Tomcat 7 + Java 8 : Invalid byte tag in constant pool: 15
- KafkaOffsetMonitor 监控工具的安装与使用
- opencv的cascade分类器源码分析
- 待面巾沾满泪水,雾前的短暂
- 【转】SQL Server 表变量和临时表的区别
- rpm 打包 关闭python 自动编译为pyc,pyo文件
- Reflections - Java 8 - invalid constant type
- HTML 的空格
- linux下mysql的root密码忘记
- 只能被实例化一次的类
- c语言算术运算表达式与赋值运算表达式的类型转换规则
- thinkphp 模糊查询组合
- 静态变量和非静态变量
- 两张图让你理解socket的TCP/UDP
- FreeCMS视频教程 将FreeCMS导入myeclipse