dex2jar icon indicating copy to clipboard operation
dex2jar copied to clipboard

java.lang.RuntimeException: Method code too large!

Open CalvinEng opened this issue 9 years ago • 11 comments

The following is the error I encountered.

There are 1 methods fail to translate. 2015-07-29 03:53:53 UTC version: [dex-reader-2.0, dex-reader-api-2.0, dex-ir-2.0, d2j-smali-2.0, d2j-base-cmd-2.0, dex-tools-2.0, dex-translator-2.0] cmdline: [com.nxp.nfc.tagwriter.apk] env: java.runtime.name: Java(TM) SE Runtime Environment java.vm.version: 25.45-b02 java.vm.vendor: Oracle Corporation java.vendor.url: http://java.oracle.com/ java.vm.name: Java HotSpot(TM) Client VM java.vm.specification.name: Java Virtual Machine Specification java.runtime.version: 1.8.0_45-b15 java.awt.graphicsenv: sun.awt.Win32GraphicsEnvironment java.endorsed.dirs: C:\Program Files (x86)\Java\jre1.8.0_45\lib\endorsed java.io.tmpdir: C:\Users\Calvin\AppData\Local\Temp
java.vm.specification.vendor: Oracle Corporation java.library.path: C:\ProgramData\Oracle\Java\javapath;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Softing\OPCToolbox\V43x\Windows\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\TortoiseSVN\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\DTS\Binn;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Microsoft SQL Server\120\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files (x86)\Skype\Phone;C:\Program Files\nodejs;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Brackets\command;C:\Users\Calvin\AppData\Roaming\npm;. java.specification.name: Java Platform API Specification java.class.version: 52.0 java.awt.printerjob: sun.awt.windows.WPrinterJob java.specification.version: 1.8 java.class.path: C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\antlr-runtime-3.5.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\asm-debug-all-4.1.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\d2j-base-cmd-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\d2j-jasmin-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\d2j-smali-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-ir-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-reader-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-reader-api-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-tools-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-translator-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dex-writer-2.0.jar;C:\Users\Calvin\Desktop\My Workspace\Maxpro\dex2jar-2.0\lib\dx-1.7.jar; java.vm.specification.version: 1.8 java.home: C:\Program Files (x86)\Java\jre1.8.0_45 java.specification.vendor: Oracle Corporation java.vm.info: mixed mode java.version: 1.8.0_45 java.ext.dirs: C:\Program Files (x86)\Java\jre1.8.0_45\lib\ext;C:\Windows\Sun\Java\lib\ext java.vendor: Oracle Corporation java.vendor.url.bug: http://bugreport.sun.com/bugreport/

CalvinEng avatar Jul 29 '15 03:07 CalvinEng

please also attach the m0.txt in the zip file

pxb1988 avatar Jul 29 '15 04:07 pxb1988

Github doesn't seems to have the option to upload files other than pictures, so I have uploaded the error zip file to google drive. Please look at the attached link.

https://drive.google.com/file/d/0B2U4p41RgtjKRFM2YWIwYW1SanM/view?usp=sharing

CalvinEng avatar Jul 29 '15 05:07 CalvinEng

the method Lcom/nxp/nfc/tagwriter/gc;.<clinit>()V contains an array, the array size is huge, so the generated instruction can't fit in a .class method.

pxb1988 avatar Jul 29 '15 08:07 pxb1988

Encounted java.lang.RuntimeException: Method code too large! Uploaded Classes-error.zip on google drive https://drive.google.com/open?id=0B0uVD6vxUmjySEhJSmVSSVM2eTA

devpilot avatar Oct 20 '15 03:10 devpilot

Hi pxb thanks for ur good Job .. I am in new for this circle.

I got same issue. How solve... I am use dex2jar 2.0.

TamilanPeriyasamy avatar Nov 27 '15 06:11 TamilanPeriyasamy

I have same problem. I'm using dex2jar Nightly build for dex2jar 20150601

GroverChouT avatar Jun 08 '16 05:06 GroverChouT

Same here. Any idea WRT a fix? or a workaround?

smurfix avatar Aug 24 '16 15:08 smurfix

I was able to work around this issue with a little elbow grease.

I got the same error as above. I looked at the summary file to find the stack trace:

java.lang.RuntimeException: Method code too large!
        at org.objectweb.asm.MethodWriter.getSize(MethodWriter.java:1872)
        at org.objectweb.asm.AsmBridge.sizeOfMethodWriter(AsmBridge.java:28)
        at com.googlecode.d2j.dex.ExDex2Asm.convertCode(ExDex2Asm.java:55)
        at com.googlecode.d2j.dex.Dex2jar$2.convertCode(Dex2jar.java:128)
        at com.googlecode.d2j.dex.Dex2Asm.convertMethod(Dex2Asm.java:509)
        at com.googlecode.d2j.dex.Dex2Asm.convertClass(Dex2Asm.java:406)
        at com.googlecode.d2j.dex.Dex2Asm.convertDex(Dex2Asm.java:422)
        at com.googlecode.d2j.dex.Dex2jar.doTranslate(Dex2jar.java:172)
        at com.googlecode.d2j.dex.Dex2jar.to(Dex2jar.java:272)
        at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:108)
        at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:288)
        at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)

Next, I found the jar file which contains that class in the lib directory: asm-debug-all-4.1.jar. Searching for "asm-debug-all-4.1.jar source code" led me here. The relevant snippet of code that's failing is:

if (code.length > 0) {
    if (code.length > 65536) {
        throw new RuntimeException("Method code too large!"); // CULPRIT
    }
    cw.newUTF8("Code");
    size += 18 + code.length + 8 * handlerCount;

What an odd test! It turns out that the java spec states that java method bodies cannot be longer than 64K, so this library is (rightfully) refusing to compile the method dex2jar has generated under the covers. But we're just trying to look at source code, not compile a program, so we don't care about that limit. Let's work around it.

The Right Thing here would be to pull down the build here, update the code, recompile it, and replace the class file. However, I -- frankly -- couldn't be arsed to do all that, so I took the much more direct (irresponsible, and lazy) approach of editing the byte code by hand.

Here's what I did:

  • Download the latest snapshot as of 2017-02-13, dex2jar-2.1-SNAPSHOT and unzip to $D2JHOME
  • Download a java bytecode editor (I used this one and unzipped to $BEHOME)
  • $ cd $D2JHOME
  • Back up the relevant library file $ cp lib/asm-debug-all-4.1.jar lib/asm-debug-all-4.1.jar.orig
  • $ cd lib
  • Extract the MethodWriter class $ unzip asm-debug-all-4.1.jar org/objectweb/asm/MethodWriter.class
  • Launch the bytecode editor and load org/objectweb/asm/MethodWriter.class (In another terminal, I used $ cd $BEHOME/bin; $ java ee.ioc.cs.jbe.browser.BrowserApplication)
  • In the bytecode editor, navigate to the getSize() method
  • In the bytecode editor, change instruction 23 ldc 65536 to a higher value (Note the code editor tab, I used ldc 524288)
  • Save the change in the bytecode editor
  • Update the MethodWriter class $ zip asm-debug-all-4.1.jar org/objectweb/asm/MethodWriter.class
  • Re-run $ $D2JHOME/d2j-dex2jar.sh application.apk -o application.jar --force
  • If that number doesn't work, try a bigger one!

Really, whether to enforce this limit or not should be an option in the asm-debug-all library. In the meantime, I've attached the updated JAR file here. (I had to rename it to ZIP for GitHub to take the file; you'll need to rename it to JAR after you download it.) Back up the existing asm-debug-all-4.1.jar file, and replace the original with the attached (renamed) file. That should work.

sigpwned avatar Feb 13 '17 18:02 sigpwned

@sigpwned Your solution is awesome but, I'm stuck with a new exception which is

java.lang.ArrayIndexOutOfBoundsException: 255 at org.objectweb.asm.MethodWriter.getSize(MethodWriter.java) at org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:775) at com.googlecode.d2j.dex.Dex2jar$1$1.visitEnd(Dex2jar.java:101) at com.googlecode.d2j.dex.Dex2Asm.convertClass(Dex2Asm.java:409) at com.googlecode.d2j.dex.Dex2Asm.convertDex(Dex2Asm.java:422) at com.googlecode.d2j.dex.Dex2jar.doTranslate(Dex2jar.java:172) at com.googlecode.d2j.dex.Dex2jar.to(Dex2jar.java:272) at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:108) at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:288) at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)

I tried to figure it out but I didn't get the point

ammaratef45 avatar Jan 04 '18 10:01 ammaratef45

@ammaratef45 Use another bytecode editor. https://github.com/GraxCode/JByteMod-Beta/releases worked for me.

ghost avatar Oct 29 '18 23:10 ghost

The asm-debug-all-4.1.jar that @sigpwned attached is outdated by now

So you should use this amazing fork which says that it fixed a lot of things and it fixed this unnecessary exception

ZXTube avatar Aug 25 '22 21:08 ZXTube