tags:

views:

972

answers:

2

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!

+9  A: 

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.

Shimi Bandiel
A: 

You can load the byte array from a file in you @BeforeClass static method. This will make sure it's loaded only once for all your unit tests.

Cem Catikkas