5 ms·
Method Size Limit in Java
- Uchikoma 15y agoWe had this problem some years ago with JSP which compiles all code into one service() method.
- nl 15y agoYes, us too. Often it is because of tag libraries that generate big try..catch..finally blocks.
- adrianmsmith 15y agoThis is a terrible limit. Code generation is necessary for all sorts of things e.g. parsers. Having to hack in code to the code generation just to split methods to get around this limit is ridiculous. I had to literally abandon months of work on one project which was generating simulation code to Java. I was generating millions of lines of code, so splitting up the method would require a main method which would call all those split methods, and then that method would get too long, etc. It all just wasn't feasible, so now I just generate C. http://www.databasesandlife.com/java-method-64k-limit/ http://www.databasesandlife.com/java-method-64k-limit/
- ig1 15y agoWhy not just have a binary tree of method calls with the leaf nodes containing your actual code ? - that way you could easily have as many methods as you wanted, and if it's auto-generated anyway it wouldn't be much extra work.
- adrianmsmith 15y ago1) It's difficult to know how long a method will be when it's compiled. Basically you have to compile it to find out. The 64k limit is on the generated byte-code, not on the source. 2) Why bother? I mean generating C (in my case) was so much easier, a simpler solution (not using a tree) is bound to have less bugs, be easier to maintain etc. I mean this is a fundamentally ridiculous limitation. One can work around it with a large amount of effort, but it shouldn't be necessary.
- halostatue 15y agoI ran into this problem a few weeks ago with some generated enums representing translatable messages driven from the database. (We are trying to make a Java API of an extant API at works with C++ and C#.) Our database has garbage in it, but that limit's just insane.
- suprgeek 15y agoThis is especially irritating considering the numerous other languages that the JVM supports now. Oracle needs to fix this limitation along with bringing in correct Generics support - not the way it is today.