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...

Recommend:java - PowerMock trying to mock static getConnection gives illegalStateException: Failed to transform class

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



 |

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的更多相关文章

  1. idea报错:error java compilation failed internal java compiler error

    idea下面报如下问题 error java compilation failed internal java compiler error 解决办法:Setting->Compiler-> ...

  2. idea Error:java: Compilation failed: internal java compiler error

    idea 遇到Error:java: Compilation failed: internal java compiler error 是提示说你当前使用的编译器jdk版本不对. 按住Ctrl+Alt ...

  3. Error:java:Compilation failed: internal java compiler error

    在IDEA中编译时出现这个错误:Error:java:Compilation failed: internal java compiler error! Information:Using javac ...

  4. idea中解决Error:java: Compilation failed: internal java compiler error的问题

    项目中,使用gradle做项目构建,当我们想更改JDK的版本时,报以下错误: Information:Using javac 1.8.0_111 to compile java sourcesInfo ...

  5. IntelliJ IDEA 运行错误:java: Compilation failed: internal java compiler error

    错误:java: Compilation failed: internal java compiler error 解决的方法: 文件 --> 设置 : 若没有模块,点击右边的把自己项目的模块添 ...

  6. Java异常 | Error:java: Compilation failed: internal java compiler error

    背景 今天网上下载了一个项目,编辑运行报如下异常: Error:java: Compilation failed: internal java compiler error 经过往经验,读项目的编译环 ...

  7. java: Compilation failed: internal java compiler error

    IDEA 编译项目出现java: Compilation failed: internal java compiler error 原因:  项目Java版本不一致 解决办法:  点击FIle> ...

  8. Spring项目出现--Error:java: Compilation failed: internal java compiler error

    错误现象 使用Idea导入新项目或升级idea或新建项目时会出现以下异常信息: Error:java: Compilation failed: internal java compiler error ...

  9. 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 ...

  10. [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 ...

随机推荐

  1. 2023年1月中国数据库排行榜:OceanBase 持续两月登顶,前四甲青云直上开新局

    一元复始,万象更新. 国产数据库在经历过耕获菑畲的一年后,产品.生态.人才队伍建设等都取得了重大的进展.2023年1月 墨天轮中国数据库流行度排行 火热出炉,本月排行榜"属性"列新 ...

  2. 封装JWT - 生成 jwt 和解析 jwt

    1. ASP.NET Core 身份验证和授权验证的功能由Authentication,Authorization中间件提供 :app.UseAuthentication(),app.UseAutho ...

  3. 001 (Python+水论文合集)为什么录这个合集,这个合集会讲哪些内容?

    博客配套视频链接: https://space.bilibili.com/383551518?spm_id_from=333.1007.0.0 b 站直接看 配套 github 链接:https:// ...

  4. Windows下如何用virtualenv创建虚拟环境

    虚拟环境可以有效的解决不同项目需要不同环境的问题,虚拟环境最大的好处就是可以将我们的开发环境进行隔离,让彼此之间不互相受影响.一.Windows下创建虚拟环境1.虚拟环境需要用到的库是virtuale ...

  5. numpy的一些基本操作

    文章目录 1.numpy数组的多种创建方式 1.1使用np.array()创建 1.2使用plt创建 1.3使用np的routine函数创建 2.numpy的常用属性 2.1shape 2.2ndim ...

  6. Go语言学习 _基础02 _条件表达式、分支、循环

    Go语言学习 _基础02 _条件表达式.分支.循环 条件表达式和switch package condition import "testing" func TestCondict ...

  7. Windows 多次制作母盘,备份文件变大的问题

    公司产品基于Win11 23H2镜像版本制作母盘,我们发现随着版本迭代,基于上一版本母盘生成新母盘备份,母盘文件会越来越大. 此处说明下镜像与母盘文件的区别, 1. 镜像是指操作系统的压缩文件,常见格 ...

  8. C++学习——访问修饰符

    一.类是什么 类是C++当中的一个集合,定义了"属性",通过类可以实例化对象,此时对象的属性就囊括在这个类当中.比如: class student { public: string ...

  9. LVM 使用与扩容总结

    转载请注明出处: LVM(Logical Volume Manager,逻辑卷管理器)是一个用于Linux系统的磁盘管理工具.它提供了一种更加灵活的存储管理机制,可以方便地进行磁盘的扩容.缩减.快照以 ...

  10. 7.Kubernetes集群YAML文件详解

    Kubernetes集群YAML文件详解 概述 k8s 集群中对资源管理和资源对象编排部署都可以通过声明样式(YAML)文件来解决,也就是可以把需要对资源对象操作编辑到YAML 格式文件中,我们把这种 ...