"Code too large" error

Dear All,

When I'm using one file which is generated by some code generation tool then javac is giving following error:

"code too large".

This code contains definition of 2 dimensional static array. This array is initialized with near about 2700 lines. while I use javac, it gives this error. If I delete some initialization lines then it get compiled.

The .class file generated after compilation is of near about 200KB.

I'm not able to find out, what's the issue.

Please help.

thanks

sushil

Dear All,

I'm using the J2SDK1.4.2_10.

I checked lots of sites, but unable to find out about the limit of number of rows java put for Array initialization.

waiting for reply.

thanks

Message was edited by:

Sushil_Naresh

[813 byte] By [Sushil_Naresha] at [2007-10-2 23:17:40]
# 1

A single method in a Java class may be at most 64KB of bytecode.

Your code generator most likely generated a method which when compiled caused more bytecode to be generated than that (most likely the array initialiser of course).

You might be able to tweak the code generator to split the code it spits out into multiple methods, which should alleviate the problem.

jwentinga at 2007-7-14 15:54:31 > top of Java-index,Developer Tools,Java Compiler...
# 2

>

> This code contains definition of 2 dimensional static

> array. This array is initialized with near about 2700

> lines. while I use javac, it gives this error. If I

> delete some initialization lines then it get

> compiled.

>

> ....

>

> I checked lots of sites, but unable to find out about

> the limit of number of rows java put for Array

> initialization.

>

Expanding a bit on the previous post

When you have code (pseudo) like the following...

class MyClass

{

private String[] s = { "a", "b", "c"}

public MyClass()

{

}

The compiler ends up producing code that basically looks like the following.

class MyClass

{

private String[] s;

private void FunnyName$Method()

{

s[0] = "a";

s[1] = "b";

s[2] = "c";

}

public MyClass()

{

FunnyName$Method();

}

And as noted java limits all methods to 64k, even the ones the compiler creates.

So your choices are

1. Rewrite the code generator.

2. Find a different way to use the code generator (like multiple inputs)

3. Don't add anything new.

jschella at 2007-7-14 15:54:31 > top of Java-index,Developer Tools,Java Compiler...