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 ...
随机推荐
- 标准库之 datetime和time 模块
一.time 模块 time模块是Python标准库中最基础.最常用的模块之一.它提供了各种处理时间的方法和函数,如获取当前时间.格式化时间.计算时间差等.time模块大部分函数的底层实现是 C 语言 ...
- 谈一谈 vuex 的运行机制
Vuex提供数据(state)来驱动视图(vue components),通过dispath派发actions,在其中可以做一些异步的操作,然后通过commit来提交mutations,最后mutat ...
- 现在 Llama 具备视觉能力并可以在你的设备上运行 - 欢迎使用 Llama 3.2
Llama 3.2 来了!今天,我们欢迎 Llama 系列的下一个版本加入 Hugging Face.这次,我们很高兴与 Meta 合作发布多模态和小型模型.在 Hub 上提供了十个开源模型 (5 个 ...
- 在 openEuler 22.03 上安装 KubeSphere 实战教程
作者:老 Z,中电信数智科技有限公司山东分公司运维架构师,云原生爱好者,目前专注于云原生运维,云原生领域技术栈涉及 Kubernetes.KubeSphere.DevOps.OpenStack.Ans ...
- 『玩转Streamlit』--页面布局
一个优秀的数据应用不仅仅是功能的强大,更在于其用户体验的打造. 而良好的页面布局,作为用户体验的重要组成部分,不仅能够提升信息的可读性,还能引导用户高效地完成操作. 反之,混乱的布局会让人感到困惑和挫 ...
- 题解:【XR-3】核心城市
题解:[XR-3]核心城市 思路一:考虑由特例推广到一般 1.很容易想到先考虑一个关键点的情况,然后再推广到一般情况. 2.一个点肯定选距离上最平衡的那个点,即树的中心.接着在中心周围贪心的选剩下的( ...
- CF2025E Card Game 题解
太喜欢这个题了,这个题出得很启发性,我以前还没见过,于是把这个题记录下来. 题面 在伯兰最流行的纸牌游戏中,使用的是一副 \(n \times m\) 纸牌.每张牌都有两个参数:花色和等级.游戏中花色 ...
- canvas绘制--圆角多边形
context.arcTo() arcTo() 方法在画布上创建介于两个切线之间的弧/曲线. JavaScript 语法: context.arcTo(x1,y1,x2,y2,r); 参数描述 参数 ...
- JDBC批处理Select语句
本文由 ImportNew - 刘志军 翻译自 Javaranch.如需转载本文,请先参见文章末尾处的转载要求. 注:为了更好理解本文,请结合原文阅读 在上一篇文章中提到了PreparedStatem ...
- javascript 实现参数重载
1.概要 在java中,同一个函数签名,比如 getUser,我们可以根据参数的不同,调用不同功能的方法.这也就是参数重载,如何在javascript也实现参数重载呢? 2.实现方法 function ...