Community
Participate
Working Groups
I'm sampling some data for my application, and I'd like to embed it as a static table. I run into this limit, which it would be nice to have removed. "The code for the static initializer is exceeding the 65535 bytes limit" Øyvind
The problem is that some VMs won't be able to execute your code if we remove this limit. This is a limitation of the .class file format. The solution is to split your code into small static methods and then you call these methods inside your static initializer.
>The problem is that some VMs won't be able to execute your code if >we remove this limit. This is a limitation of the .class file format. I see. What mislead me to think was a problem in Eclipse is that this limit does not exist for non-static initialisations(or if it does, I do not get any error messages). Øyvind
Pls double check
Check: // this compiles private final class A // this does not //private static class A { final private double[] foo= { 0.000000e+000, 0.000000e+000, 2.442002e-004, 1.392198e-005 ,4.884005e-004, 2.797402e-005 ,7.326007e-004, 4.228620e-005 .... lots of data follows
Please attach the whole source. I will investigate.
Created attachment 2959 [details] Produces unexpected error I'm trying to remove NDA stuff from the testcase I'm uploading and I discovered this. I didn't know there was a size limit to .class files. "The code of method Foo is exceeding the 65535 bytes limit"
Created attachment 2961 [details] demonstrates differences in class file size limit for static and final See first of lines on how to modify the file to compile when using "final" instead of "static".
Ok. The reason why it works when you remove the first static is because you move the code generation of the first array into a constructor and you keep all other static fields inside the <clinit>. If you remove all your static fields to have only instance fields, you will have the same problem. Compiled 8214 lines in 2266 ms (3624.8 lines/s) ---------- 1. ERROR in D:\temp\Foo.java (at line 5) public class Foo ^^^ The code of method Foo is exceeding the 65535 bytes limit ---------- 1 problem (1 error) In fact we might want to improve the error message. It should say this is a constructor. Your solution is either to move each static fiel initialization in a separate method and call all these methods inside your static initializer or you initialize your arrays using a for loop. Ok to close?
>Ok to close? Yup. I agree that if anything should be done, it would be to improve the error message. Øyvind
Error message fixed. We now distinguish between constructors and methods. I also added the parameters in the error message. Fixed and released in 2.1 stream.
Verified.