-1

Please look at the below scenario: (PS: I am not trying to resolve the code too large compiler error as there are multiple elegant ways of doing it.)

We are getting "Code too large" compilation error for one of our class. This class contains public String fields for label ID and value. We use this class for localization, except for English all other language labels come from .properties files.

The reason we are getting this error is because we have a static block in which using reflection we are populating a HashMap with all public fields and their value. The number of fields have gone up to the extinct where we are crossing the 64K limit for a static method. One of the most feasible solution was to use .properties files for English labels as well.

The issue is resolved, and here is the proposed solution:
For the sake of discussion I will be calling this class MyLabels. We defined a super class for MyLabels called MyLabelsExt. And now we are adding labels into the super class instead of the MyLabels. By running some tests we confirmed that the map that we initialize in MyLables class contains all the fields from both MyLabels and MyLabelsExt class.

Question: How come the 64K limit error was by passed when we started using the super class.

Thanks, Manish.

  • Does your file contain any invalid characters which cant be read? – Klemens Morbe Mar 17 '14 at 08:06
  • Why do you need your own `MyLabels` class if you're using properties files? Doesn't the `Properties` class work for your requirements? – Dawood ibn Kareem Mar 17 '14 at 08:12
  • If you need localization why not just use `ResourceBundle`? Or if you have property files in UTF-8 (which `ResourceBundle` cannot handle), there is an alternative library which does UTF-8 – fge Mar 17 '14 at 08:15
  • possible duplicate of ["code too large" compilation error in java](http://stackoverflow.com/questions/2407912/code-too-large-compilation-error-in-java) – Andremoniy Mar 17 '14 at 08:36

1 Answers1

1

To be honest that seems like a horrible solution. Your use of a hash map which holds reference to fields (?) sounds very questionable as well.

IMO you should hold the mapping between message ID and the message as plain values. For example, something like this:

Map<String, Map<String, String>> lang_id_message;

String text = message.get("en").get("please.pay.the.developer");

Such map can be populated from a file, like a property file, and you wouldn't hit such platform limits. The definition of message will be also much more manageable; for example, assigning error codes to them are easy if they are in a property file, but is very annoying when they sit in a Java source file.

Enno Shioji
  • 26,542
  • 13
  • 70
  • 109
  • The field looks like: `code`public String LABEL = "Label";`code` And the map looks like: `code`public static final Map fieldMap;`code` I agree with your suggestion, but I need help on how this problem got resolved using a super class. What happened to the 64K limit. – user3427936 Mar 17 '14 at 08:58