I have a java file having one method that is very big, it compile successfully, but after running it throws java.lang.ClassFormatError: Invalid method Code length 72521 in class file
I research on vm spec file JVM restricts the maximum size of a method to 65536 bytes. The JVM spec has mentioned about this restriction
Is there is any work around for this ?
You should probably split your method into two or more sub-methods, which you call in sequence from the main one. In fact, it should probably be way more than two. Encapsulating your code into multiple methods will make it muuuuuch easier to understand than one Dickens-length method. And hey, you might be able to re-use them elsewhere.
If you absolutely can’t break up your method, maybe you could try taking out extraneous whitespace? This is called minification, and there’s probably a utility that will do it for Java. All of this is with the caveat that it will make your epic method even less readable, so don’t do this if you’re going to want to change it in the future ever ever.
On a related note, congratulations on writing a method so long you broke java. That’s actually really impressive.