chcchangchc / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Failed to transform class with name foo.TempTest Reason: 3 #349

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm getting a "Failed to transform class with name foo.TempTest Reason: 3" 
error when mocking a static method. 

My test is this:

@RunWith(PowerMockRunner.class)  
@PrepareForTest({Utils2.class})  
public class TempTest {

    @Test
    public void say() {
    }
}

And Utils2 class:

public class Utils2 {
    public static String say(String s) {
        return s;
    }
}

The stack trace when exception is thrown is:

java.lang.IllegalStateException: Failed to transform class with name 
com.crossfence.service.TempTest. Reason: 3
    ...
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
    at javassist.bytecode.ByteArray.write16bit(ByteArray.java:40)
    at javassist.bytecode.StackMapTable$Shifter.update(StackMapTable.java:744)
    ...
    at javassist.expr.FieldAccess.replace(FieldAccess.java:213)
    at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:267)
    ...
    at javassist.CtClassType.instrument(CtClassType.java:1288)
    at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:75)
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:203)
    ... 29 more

I got the exception when adding this test to an existing project. However, it 
works fine if I create a new project with just these two classes. Therefore 
this could be an envrionement issue. 

I'm using these verions:
junit 4.8.2, easymock 3.0, powermock 1.4.10, and javassist 3.12.0.GA.

The operating system is Windows 7.

How do I troubleshoot this? Are there loggings I can turn on?

Let me know if you need more information.

Thanks!

Original issue reported on code.google.com by zhaoshan...@gmail.com on 12 Oct 2011 at 3:44

GoogleCodeExporter commented 9 years ago
Hi, 

Try upgraded to Javassist 3.15 GA and see if it works

Original comment by johan.ha...@gmail.com on 13 Oct 2011 at 6:57

GoogleCodeExporter commented 9 years ago
Worked. Thanks! Actually Javassist 3.6 was used. 3.12 GA works as well.

Original comment by zhaoshan...@gmail.com on 13 Oct 2011 at 2:27

GoogleCodeExporter commented 9 years ago
It's important that you use the correct dependencies otherwise PowerMock won't 
work.

Original comment by johan.ha...@gmail.com on 13 Oct 2011 at 2:35