Skip to content

Commit

Permalink
Fix error initializeEnumMap() is exceeding the 65535 bytes limit (#9954)
Browse files Browse the repository at this point in the history
During build we hit a the error
>The code of method initializeEnumMap() is exceeding the 65535 bytes
limit.

This gets around the error by splitting the method into as many methods
as needed.
  • Loading branch information
pmskintner authored Jul 16, 2024
1 parent aabb575 commit 0709ea1
Showing 1 changed file with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
*/
public class AutoBeanFactoryGenerator extends Generator {

private static final int MAX_ENUMS_PER_METHOD = 2000;

private GeneratorContext context;
private String simpleSourceName;
private TreeLogger logger;
Expand Down Expand Up @@ -372,14 +374,37 @@ private void writeEnumSetup(SourceWriter sw) {
list.add(entry.getKey());
}

sw.println("@Override protected void initializeEnumMap() {");
sw.indent();
int methodCount = 0;
int enumPerMethodCount = MAX_ENUMS_PER_METHOD + MAX_ENUMS_PER_METHOD;
for (Map.Entry<JEnumConstant, String> entry : model.getEnumTokenMap().entrySet()) {
if (enumPerMethodCount >= MAX_ENUMS_PER_METHOD) {
if (methodCount != 0) {
sw.outdent();
sw.println("}");
}
enumPerMethodCount = 0;
methodCount++;
sw.println("private void initializeEnumMap_%d() {", methodCount);
sw.indent();
}

// enumToStringMap.put(Enum.FOO, "FOO");
sw.println("enumToStringMap.put(%s.%s, \"%s\");", entry.getKey().getEnclosingType()
.getQualifiedSourceName(), entry.getKey().getName(), entry.getValue());

enumPerMethodCount++;
}

for (Map.Entry<String, List<JEnumConstant>> entry : map.entrySet()) {
if (enumPerMethodCount >= MAX_ENUMS_PER_METHOD) {
sw.outdent();
sw.println("}");
enumPerMethodCount = 0;
methodCount++;
sw.println("private void initializeEnumMap_%d() {", methodCount);
sw.indent();
}

String listExpr;
if (entry.getValue().size() == 1) {
JEnumConstant e = entry.getValue().get(0);
Expand All @@ -405,6 +430,19 @@ private void writeEnumSetup(SourceWriter sw) {
listExpr = sb.toString();
}
sw.println("stringsToEnumsMap.put(\"%s\", %s);", entry.getKey(), listExpr);

enumPerMethodCount += entry.getValue().size();
}

if (methodCount != 0) {
sw.outdent();
sw.println("}");
}

sw.println("@Override protected void initializeEnumMap() {");
sw.indent();
for (int i = 1; i <= methodCount; i++) {
sw.println("initializeEnumMap_%d();", i);
}
sw.outdent();
sw.println("}");
Expand Down

0 comments on commit 0709ea1

Please sign in to comment.