异常说明

使用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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55

看了一篇文章说是 代码中是用的解析字节码的库 既不兼容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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

扫描代码:

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());
}
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

REF

Reflections - Java 8 - invalid constant type的更多相关文章

  1. Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18

    工程启动的时候有报下面这个错误的,更新下工程的jar包依赖,然后在工程的pom文件里加上下面的jar包 Caused by: java.lang.RuntimeException: java.io.I ...

  2. 运行报错:java.io.IOException: invalid constant type: 15

    jdk,tomcat更新到jdk1.8与 tomcat8 运行报错:java.io.IOException: invalid constant type: 15 pom.xml文件中更新javassi ...

  3. mockito 异常Reason: java.io.IOException: invalid constant type: 18

    原因: mockito内部使用的javassit的版本不一致导致的,修改为一直版本即可. 异常内容: /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jd ...

  4. java.lang.RuntimeException: java.io.IOException: invalid constant type: 15

    java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 controller通过dubbo调用servic ...

  5. invalid constant type: 18

    javassist 3.18以下的版本不支持在JDK1.8下运行

  6. Invalid mime type "application nd.ms-excel; charset=utf-8;charset=utf-8": does not contain '/'

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...

  7. jedis:exception is java.lang.VerifyError: Bad type on operand stack

    项目中需要用到缓存,经过比较后,选择了redis,客户端使用jedis连接,也使用到了spring提供的spring-data-redis.配置正确后启动tomcat,发现如下异常: ======== ...

  8. 发生了Post错误:错误代码40005,微信返回错误信息:invalid file type

    给客户部署 PxxCms, 使用群发功能发送图文的的时候提示: 发生了Post错误:错误代码40005,微信返回错误信息:invalid file type, 没学过php伤不起 ... Google ...

  9. Caused by: java.lang.IllegalArgumentException: argument type mismatch

    下面是我的报错信息 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java: ...

随机推荐

  1. ECharts图表实战经验1:如何设置图表同序列不同数据点的独立颜色值

    最近有不少朋友在追问这样一个问题:我单序列的柱状图,我想让每一个根柱子的颜色都不一样,应该如何做? 针对这个问题,其实我只想说你压根没有认真看完或者查找ECharts官方的示例,官方能够找到的示例有: ...

  2. SqlServer 登录和卸载

    一.数据库简介 SQLServer环境配置 安装好数据库以后怎么启用sa账号来访问数据库. 1.先用windows账号登录数据库. 2.启用windows身份验证方式和sql server身份验证方式 ...

  3. php7.27: export excel from mysql

    https://stackoverflow.com/questions/15699301/export-mysql-data-to-excel-in-php https://github.com/PH ...

  4. python中传值和传地址问题

    在python中,还没有对这个知识点有一个详细的定义,很模糊的说明了,通过下面代码,可以观察出来,什么时候传的是值,什么时候传的是地址 有时候会发现自己的数据发生变化,可能就是这个原因,python的 ...

  5. element-ui 的el-button组件中添加自定义颜色和图标

    我使用的element-ui的版本是V1.4.13. 如上图所示,如果使用el-button,加颜色是可以通过设置type属性的值,加图标就设置icon属性的值. 现在产品给了一个需求,就是自定义的很 ...

  6. 2018-02-17 中文代码示例[译]Scala中创建隐式函数

    前言: 学习Scala时, 顺便翻译一下自己有兴趣的文章. 代码中所有命名都中文化了(不是翻译). 比如原文用的是甜甜圈的例子. 原文: Scala Tutorial - Learn How To C ...

  7. 如何判断一个 APP页面是否是H5页面

    1.无网络断开网络,显示404或则错误页面的是H5 2.页面布局a.在手机设置.开发者选项中开启显示布局边界功能:b.进入应用查看布局边界:c.原生应用可以看到各个控件的布局边界,H5只有整个页面的一 ...

  8. Salesforce的数据安全防护措施

    通过Salesforce,我们可以配置或开发出功能强大的网络应用.与此同时,无论作为管理员还是开发者,我们都要面对数据安全的问题. 常见的数据安全隐患有: SQL注入 跨站脚本攻击 跨站请求伪造 点击 ...

  9. Ansible--inventory

    简介 Inventory 是 Ansible 管理主机信息的配置文件,相当于系统 HOSTS 文件的功能,默认存放在 /etc/ansible/hosts.为方便批量管理主机,便捷使用其中的主机分组, ...

  10. 安卓开发_WebView设置打开网页缩放问题

    之前实现打开网页的方式,测试后,发现不能够对网页进行缩放操作,这对部分网页来说是十分不便的, 百度了一下解决方案 其实只需要加几行代码就可以实现网页缩放操作 settings.setUseWideVi ...