Thoppan / powermock

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

@PrepareForTest causes LocalVariableTable error when using log4j #266

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a class to test that defines Logger from log4j
2. Create a unit test for that class with the @PrepareForTest Attribute
3. Run the test case with the "Run as JUnit" in eclipse
4. Error occurs with "Invalid length XXXX in LocalVariableTable"

What is the expected output? What do you see instead?
It should not throw an exception

What version of the product are you using? On what operating system?
powermock-mockito-1.3.8-full.jar

Please provide any additional information below.
*Removing the Logger prevents the exception.
*Removing the Attribute prevents the exception.

Original issue reported on code.google.com by kevin.ki...@gmail.com on 9 Jul 2010 at 9:12

GoogleCodeExporter commented 9 years ago
Could it be a bug in Javassist?

Original comment by johan.ha...@gmail.com on 14 Jul 2010 at 12:18

GoogleCodeExporter commented 9 years ago
I don't think so. Here is the stack trace:java.lang.ClassFormatError: Invalid 
length 493 in LocalVariableTable in class file 
com/inlethd/grapeshot/library/element/Channel
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:211)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:146)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
    at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
    at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:351)
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070)
    at java.lang.Class.getAnnotations(Class.java:3050)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.classAnnotations(PowerMockJUnit44RunnerDelegateImpl.java:178)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.getDescription(PowerMockJUnit44RunnerDelegateImpl.java:170)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getDescription(JUnit4TestSuiteChunkerImpl.java:182)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.getDescription(AbstractCommonPowerMockRunner.java:50)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.sendTree(JUnit4TestClassReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.sendTrees(RemoteTestRunner.java:476)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Original comment by kevin.ki...@gmail.com on 14 Jul 2010 at 10:16

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Looks similar to https://jira.jboss.org/browse/JASSIST-99 but it should be 
fixed in version 3.12.

Original comment by johan.ha...@gmail.com on 15 Jul 2010 at 9:09

GoogleCodeExporter commented 9 years ago
Which version of javassist are you using?

Original comment by johan.ha...@gmail.com on 15 Jul 2010 at 9:12

GoogleCodeExporter commented 9 years ago
Don't know. How do I find out?

Original comment by kevin.ki...@gmail.com on 16 Jul 2010 at 4:18

GoogleCodeExporter commented 9 years ago
You need to check in your classpath. If you're using Maven do "mvn 
dependency:tree". A new version of Javassist (3.13) was just released. Please 
try if you have the same issue with that version.

Original comment by johan.ha...@gmail.com on 20 Jul 2010 at 7:23

GoogleCodeExporter commented 9 years ago
Looks like this is fixed in the new release. powermock-mockito-1.4 using the 
new javassist-3.13.0.GA.jar.

Original comment by kevin.ki...@gmail.com on 3 Sep 2010 at 11:54

GoogleCodeExporter commented 9 years ago
Great, then I close this issue.

Original comment by johan.ha...@gmail.com on 8 Sep 2010 at 9:11

GoogleCodeExporter commented 9 years ago
Hi, I'm still getting this error. I'm using powermock-core-1.5.1.jar and 
javassist-3.16.1-GA.jar.

java.lang.ClassFormatError: Invalid length 4012 in LocalVariableTable in class 
file lc/commonservice/repository/LCActorRepository
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:222)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:147)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
    at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
    at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:351)
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070)
    at java.lang.Class.getAnnotations(Class.java:3050)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.classAnnotations(PowerMockJUnit44RunnerDelegateImpl.java:165)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.getDescription(PowerMockJUnit44RunnerDelegateImpl.java:157)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getDescription(JUnit4TestSuiteChunkerImpl.java:171)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.getDescription(AbstractCommonPowerMockRunner.java:47)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.sendTree(JUnit4TestClassReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.sendTrees(RemoteTestRunner.java:476)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Original comment by lin.xing...@gmail.com on 10 Mar 2014 at 7:16

GoogleCodeExporter commented 9 years ago
Sorry, I was using javassist-3.11 actually. After using 
javassist-3.12.1.GA.jar, I make it working fine. Thanks.

Original comment by lin.xing...@gmail.com on 10 Mar 2014 at 9:20

GoogleCodeExporter commented 9 years ago
Javassist 3.11 is really old, please use the latest version

Original comment by johan.ha...@gmail.com on 11 Mar 2014 at 11:28

GoogleCodeExporter commented 9 years ago
hi,guys
I am getting this issue with javassist3.15GA
anyone can help~ 

Original comment by Ferrucci...@gmail.com on 7 May 2014 at 3:09

GoogleCodeExporter commented 9 years ago
Upgrade to a newer Javassist release.

Original comment by johan.ha...@gmail.com on 7 May 2014 at 4:48

GoogleCodeExporter commented 9 years ago
Hi,

This error exists even with the latest version powermock & javassist.

Versions of libs:
powermock-core-1.5.4.jar and javassist-3.18.1-GA.jar.

Is there a remedy for this problem?

Original comment by ashok.k...@gmail.com on 29 May 2014 at 7:19

GoogleCodeExporter commented 9 years ago
Not that I know of, there may be some tips here: 
https://code.google.com/p/powermock/issues/detail?id=355

Original comment by johan.ha...@gmail.com on 29 May 2014 at 2:37