Alex Rivera | Logout

javac error "code too large"?

Asked 2008-10-28T12:30:13.197
21

I have a unit test where I have statically defined a quite large byte array (over 8000 bytes) as the byte data of a file I don't want to read every time I run my unit test.

private static final byte[] FILE_DATA = new byte[] {
12,-2,123,................
}

This compiles fine within Eclipse, but when compiling via Ant script I get the following error:

[javac] C:\workspace\CCUnitTest\src\UnitTest.java:72: code too large
[javac]     private static final byte[] FILE_DATA = new byte[] {
[javac]                                 ^

Any ideas why and how I can avoid this?


Answer: Shimi's answer did the trick. I moved the byte array out to a separate class and it compiled fine. Thanks!

Edit
Report

1 Answer

26

Methods in Java are restricted to 64k in the byte code. Static initializations are done in a single method (see link)
You may try to load the array data from a file.

answered 2008-10-28T12:34:50.817

Your Answer