java - Powermock-Failed to transform class with name...ArrayIndexOutOfBoundsException: 3
I'm trying to run a junit test.
i'm using: junit 4.10,
easymock 3.0,
powermock-core 1.4.10 (uses javassist 3.15.0-GA),
powermock-module-junit4 1.4.10,
powermock-api-easymock 1.4.10
with all the appropriate dependencies.
I have also try with powermock-core 1.5.5(javassist 3.18.0-GA)
(please note that only one more dependency ognl (uses javassist 3.7.ga)
test class:
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClassToBeTested.class})
public class MyClassToBeTestedTest{
private MyClassToBeTested myClassToBeTested;
@Before
public void setUp() {
// Partial mock with powermock
myClassToBeTested = PowerMock.createPartialMock(MyClassToBeTested.class, "testMethod");
}
@Test // IF I COMMENT THE @Test ANNOTATION AND
public void testMethod() { // ALSO THE testMethod() THERE IS NO EXCEPTION
}
}
stack trace:
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0,08 sec
[junit]
[junit] Testcase: initializationError(com.myProject.MyClassToBeTested): Caused an ERROR
[junit] Failed to transform class with name com.myProject.MyClassToBeTested. Reason: 3
[junit] java.lang.IllegalStateException: Failed to transform class with name com.myProject.MyClassToBeTested. Reason: 3
[junit] at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:207)
[junit] at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:145)
[junit] at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:249)
[junit] at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java
3)
[junit] at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java
)
[junit] at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:217)
[junit] at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
[junit] at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
[junit] at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:26)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[junit] Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
[junit] at javassist.bytecode.ByteArray.write16bit(ByteArray.java:40)
[junit] at javassist.bytecode.StackMapTable$Shifter.update(StackMapTable.java:744)
[junit] at javassist.bytecode.StackMapTable$Shifter.sameFrame(StackMapTable.java:720)
[junit] at javassist.bytecode.StackMapTable$Walker.stackMapFrames(StackMapTable.java:194)
[junit] at javassist.bytecode.StackMapTable$Walker.parse(StackMapTable.java:179)
[junit] at javassist.bytecode.StackMapTable$Shifter.doit(StackMapTable.java:714)
[junit] at javassist.bytecode.StackMapTable.shiftPc(StackMapTable.java:693)
[junit] at javassist.bytecode.CodeIterator.insertGap0(CodeIterator.java:676)
[junit] at javassist.bytecode.CodeIterator.insertGap(CodeIterator.java:636)
[junit] at javassist.bytecode.CodeIterator.insertGapCore(CodeIterator.java:467)
[junit] at javassist.bytecode.CodeIterator.insertGap(CodeIterator.java:413)
[junit] at javassist.expr.Expr.replace0(Expr.java:298)
[junit] at javassist.expr.FieldAccess.replace(FieldAccess.java:213)
[junit] at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:267)
[junit] at javassist.expr.ExprEditor.loopBody(ExprEditor.java:197)
[junit] at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
[junit] at javassist.CtClassType.instrument(CtClassType.java:1289)
[junit] at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:75)
[junit] at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:203)
thank you for any given advice...
org.junit.Test;import org.junit.runner.RunWith;import org.mockito.Mockito;import org.powermock.core.classloader.annotations.PrepareForTest;import org.powermock.modules.junit4.PowerMockRunner;@RunWith(PowerMockRunner.class)@PrepareFo
java powermock | this question edited Aug 5 '14 at 7:57 asked Aug 4 '14 at 15:25 sei 6 4 did you work it out yourself? – Fletch Oct 8 '14 at 15:09 No... i tried but i didn't manage to find what was the problem. I finally changed to Jmockit. – sei Oct 8 '14 at 15:23
|
1 Answers
1
I know this is an old question, but I got exactly the same error recently after changing some other dependencies. It appears to be a bug in versions of javassist pre 3.18.2 (I note you were using 3.18.1).
I fixed it by upgrading Powermock to version 1.6.2 and explicitly adding a dependency on Javassist 3.19.0-GA.
This bug was fixed in Javassist 3.18.2-GA : https://issues.jboss.org/browse/JASSIST-223
| this answer answered Sep 9 '15 at 4:04 Jumwah 119 8
|
Recommend:java - PowerMock & JavaAssist "Failed to transform class"
sts with PowerMock. I have looked at many SO responses already, and tried many combinations of PowerMock, JUnit, JavaAssist (overriding dependencies) but can't find a combination that works for this class. (Some combinations of PowerMock, J
oriUlr:http://stackoverflow.com/questions/25122180/powermock-failed-to-transform-class-with-name-arrayindexoutofboundsexception
java - Powermock-Failed to transform class with name...ArrayIndexOutOfBoundsException: 3的更多相关文章
- idea报错:error java compilation failed internal java compiler error
idea下面报如下问题 error java compilation failed internal java compiler error 解决办法:Setting->Compiler-> ...
- idea Error:java: Compilation failed: internal java compiler error
idea 遇到Error:java: Compilation failed: internal java compiler error 是提示说你当前使用的编译器jdk版本不对. 按住Ctrl+Alt ...
- Error:java:Compilation failed: internal java compiler error
在IDEA中编译时出现这个错误:Error:java:Compilation failed: internal java compiler error! Information:Using javac ...
- idea中解决Error:java: Compilation failed: internal java compiler error的问题
项目中,使用gradle做项目构建,当我们想更改JDK的版本时,报以下错误: Information:Using javac 1.8.0_111 to compile java sourcesInfo ...
- IntelliJ IDEA 运行错误:java: Compilation failed: internal java compiler error
错误:java: Compilation failed: internal java compiler error 解决的方法: 文件 --> 设置 : 若没有模块,点击右边的把自己项目的模块添 ...
- Java异常 | Error:java: Compilation failed: internal java compiler error
背景 今天网上下载了一个项目,编辑运行报如下异常: Error:java: Compilation failed: internal java compiler error 经过往经验,读项目的编译环 ...
- java: Compilation failed: internal java compiler error
IDEA 编译项目出现java: Compilation failed: internal java compiler error 原因: 项目Java版本不一致 解决办法: 点击FIle> ...
- Spring项目出现--Error:java: Compilation failed: internal java compiler error
错误现象 使用Idea导入新项目或升级idea或新建项目时会出现以下异常信息: Error:java: Compilation failed: internal java compiler error ...
- Java Error: Failed to validate certificate. The application will not be executed
Hi, last week a customer had the problem that he wants to connect to the administration interface of ...
- [Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
Background: Servlet version 3.1(3.0之后就有了@WebServlet注解) Error 严重: Failed to destroy end point associa ...
随机推荐
- iOS解决嵌套在ScrollView中的TableView滑动手势冲突问题
在项目开发中用到了这种需求,顶部两个选项卡,底部列表有侧滑手势,布局是就不说了,遇到的问题是左滑的时候添加滑动手势效果.一直纠结了很久,后来想到可能是手势冲突的问题. 解决办法开启多手势代理即可,我是 ...
- 75.cancat是否会改变原数组
cancat 用来链接 2 个数组,不会改变原数组 :
- 深入浅出 Kubernetes 项目网关与应用路由
KubeSphere 项目网关与应用路由提供了一种聚合服务的方式,将集群的内部服务通过一个外部可访问的 IP 地址以 HTTP 或 HTTPs 暴露给集群外部.应用路由定义了这些服务的访问规则,用户可 ...
- KubeSphere 社区双周报 | KubeKey v3.0.7 发布 | 2023-02-03
KubeSphere 从诞生的第一天起便秉持着开源.开放的理念,并且以社区的方式成长,如今 KubeSphere 已经成为全球最受欢迎的开源容器平台之一.这些都离不开社区小伙伴的共同努力,你们为 Ku ...
- es之增删改查
查询 index: GET task_results/_search/ 普通查询: {"query":{"bool":{"must":[{& ...
- 自学PHP笔记(二)PHP数据类型
PHP数据类型可支持以下8种类型: 类型 说明 string 字符串 boolean 布尔值 integer 整型 float 浮点型 array 数组 object 对象 resource 资源 N ...
- sqluldr2linux64.bin命令行下的Oracle数据导出工具
sqluldr2.bin是Oracle数据库下,数据导出的工具 (1)query导出 ./sqluldr2.bin user=用户/密码@主机IP/数据库名 query="select ...
- ROS入门21讲(3)
七.话题消息的定义和使用 目的:实现Publisher 与 Subscriber 之间的传输 1.自定义话题消息 如何自定义话题消息? ①完成数据接口的定义---定义msg文件 Person.msg ...
- transformer论文解读
1. 相关工作 2. 模型架构 3. 如何理解 Layer Norm 4. Encoder 和 Decoder 结构 5. 从 attention 到 Scaled Dot-Product Atten ...
- vue3 js 学习笔记
Vue3-js 学习笔记 目录 Vue3-js 学习笔记 目录 前言 reactive 数据绑定 事件绑定 生命函数周期 计算属性-computed props emit-自定义事件 ref-获取元素 ...