aspose file tools*
The moose likes Java in General and the fly likes code too large for try statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "code too large for try statement" Watch "code too large for try statement" New topic
Author

code too large for try statement

Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
I am getting error on UNIX env "code too large for try statement" in jdk 1.5. Though it compiles in eclipse jdk 1.6. Would anyone help?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Wow. That must be some bad code. Is it a JSP?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
No. its not a jsp. It simply java code having 38K lines.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You'll need to break the code inside that try block up into separate methods, then have the (now much shorter) code inside the try block call those methods.


[Jess in Action][AskingGoodQuestions]
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
I understand it...But what is the reason i am able to compile it on eclipse jdk 1.5
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The real limitation(s) are some dimensions in the class file format specification: there are a number of short integers used as dimensions that limit the size of a method or of a jump to 32,767 bytes. Compilers have a little leeway on how they implement things, and a smarter compiler might generate tighter code such that a large block of code might barely fit using one compiler, but not fit when using another.

So is this hand-written code, or machine-generated code? (That's what the JSP question was getting at.) Writing this much code by hand in a single method is hard to imagine, but you can easily imagine a FORTRAN translator that does it, for example, or a complex machine-generated parser.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Patricia Samuel wrote:No. its not a jsp. It simply java code having 38K lines.


I have been in computing for over 45 years and I have never ever seen a single method anything like 38K lines long. The longest human generated single method I have seen is about 2.5K lines (FORTRAN) and the longest computer generated single method was about 8K lines (CSMP compiled to FORTRAN).

I would love to know what motivates a design requiring this horrendous method.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

One place I consulted at had a 30k+ line file that was a giant set of nested if-elses, maintained by hand (but not in Eclipse, because it made Eclipse crash).

But yes, you'll need to break it up into smaller methods. Preferably smaller classes and files, too. We had the same issue on a Solaris box, but that was with a JSP that had been built with static includes :/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
have look at the JVM specifications. You find that the largest method permissible is very slightly less than 64kB in bytecode, so your long block is presumably exceeding 64kB.
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
so many speculations!!!

Folks, its a talend generted code and try block has 7000 lines of code. it works perfectly in eclipse. I see no compilation error. But when i use my build.xml on unix environment it throws code too large for try statement. Any help!!!

Patricia
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Copy the block into a standalone class and compile that from the command line. See what happens.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Patricia Samuel wrote:so many speculations!!!

Folks, its a talend generted code and try block has 7000 lines of code. it works perfectly in eclipse. I see no compilation error. But when i use my build.xml on unix environment it throws code too large for try statement. Any help!!!

Patricia

It's a different JVM. It will have different limitations. The error message is telling you precisely what the issue is; you'll need to find a way around it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
David Newton wrote: . . . It's a different JVM. It will have different limitations. . . .
Oh, I'd never heard of talend before. Didn't know it is a different VM.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No no, OP said code was generated by "talend". But it's running on a different JVM than the one he was testing on.

Personally I wouldn't think 7000 lines in a try block would be too many (from a technical standpoint), but apparently I'd wrong when I think that.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Thank you for clearing up my misunderstanding.


But the bit about 64kB should apply unchanged to all JVMs? 7000 lines of code will be ≫64kB, but it will presumably be much less when converted to bytecode. But 38000+ lines??
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 350
might this help?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

David Newton wrote:How?


If the Eclipse compiler manages to create valid class files from the code, but Sun's doesn't, then this tool will let you use the Eclipse compiler to build outside of Eclipse. Sounds like a good idea actually, since apparently she has no control over the code itself.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Campbell Ritchie wrote:But the bit about 64kB should apply unchanged to all JVMs? 7000 lines of code will be ≫64kB, but it will presumably be much less when converted to bytecode. But 38000+ lines??

My example, turns out, has multiple methods in it; the file itself is just over 30k lines, but there are more methods in it than I thought.

Not sure about the JSP issue we had; it was awhile ago.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
If the file is 30000 lines long, but contains several methods, then it is likely each method will be of the permissible size.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yeah, that's what I'm saying. I had remembered there being only a few methods, but I was mistaken. They "refactored". Sort of.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Yes, refactoring takes all the fun out of it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code too large for try statement