title: java.lang.ClassFormatError: Invalid method Code length while using PowerMock
body: <p>I am running JUnit case with PowerMock in jdk7 using the below libraries :</p>
  
  <pre><code>cglib-nodep-2.2.2.jar
  javassist-3.19.0-GA.jar
  junit-4.12.jar
  mockito-all-1.10.19.jar
  objenesis-2.1.jar
  powermock-mockito-1.6.2-full.jar
  </code></pre>
  
  <p>Below is code snippet from my Unit Test in which I am using PowerMock </p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest(ValidateBindingImpl.class)
  public class ValidateBindingImplTest{
  
  //more code follows
  }
  </code></pre>
  
  <p>While executing this test case I am getting following error:</p>
  
  <pre><code>java.lang.ClassFormatError: Invalid method Code length 119842 in class file com/v1/ValidateBindingImpl
      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:269)
  at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
  at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:249)
  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:3079)
  at java.lang.Class.getAnnotation(Class.java:3038)
  at org.junit.internal.MethodSorter.getDeclaredMethods(MethodSorter.java:52)
  at org.junit.internal.runners.TestClass.getAnnotatedMethods(TestClass.java:45)
  at org.junit.internal.runners.MethodValidator.validateTestMethods(MethodValidator.java:71)
  at org.junit.internal.runners.MethodValidator.validateStaticMethods(MethodValidator.java:44)
  at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:50)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.validate(PowerMockJUnit44RunnerDelegateImpl.java:108)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.&lt;init&gt;(PowerMockJUnit44RunnerDelegateImpl.java:70)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl.&lt;init&gt;(PowerMockJUnit47RunnerDelegateImpl.java:42)
  at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl.&lt;init&gt;(PowerMockJUnit49RunnerDelegateImpl.java:25)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:156)
  at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
  at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
  at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.&lt;init&gt;(JUnit4TestSuiteChunkerImpl.java:61)
  at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.&lt;init&gt;(AbstractCommonPowerMockRunner.java:32)
  at org.powermock.modules.junit4.PowerMockRunner.&lt;init&gt;(PowerMockRunner.java:34)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
  at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
  at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
  at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
  at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
  at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.&lt;init&gt;(JUnit4TestReference.java:33)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.&lt;init&gt;(JUnit4TestClassReference.java:25)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  </code></pre>
  
  <p>Found similar post discussed <a href="https://stackoverflow.com/questions/32582673/powermock-is-throwing-java-lang-classformaterror-with-struts2-action">here</a> and <a href="https://stackoverflow.com/questions/7010665/testng-emma-cobertura-coverage-and-jdk-7-result-in-classformaterror-and-verif">here</a> based on which I tried adding -XX:-UseSplitVerifier in VM arguments but it didn't work.</p>
  
  <p>Moreover I understand that the error seem to occur due to lengthy method in my class file but as its my organization code I wont be able modify/split the method as suggested in some posts online.</p>