Copilot commented on code in PR #6888: URL: https://github.com/apache/incubator-kie/pull/6888#discussion_r3827817276
########## kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/ProcessGeneratorCodeSizeTest.java: ########## @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.kie.kogito.codegen.process; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.List; + +import org.drools.codegen.common.GeneratedFile; +import org.junit.jupiter.api.Test; +import org.kie.kogito.codegen.api.context.KogitoBuildContext; +import org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext; +import org.kie.kogito.codegen.core.io.CollectedResourceProducer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +public class ProcessGeneratorCodeSizeTest { + + private static final Path BASE_PATH = Paths.get("src/test/resources/").toAbsolutePath(); + + @Test + void largeBpmnCompilesSuccessfully() { + Path bpmnFile = BASE_PATH.resolve("codetoolarge/repro-fails.bpmn"); + + KogitoBuildContext context = JavaKogitoBuildContext.builder() + .withApplicationProperties(bpmnFile.getParent().toFile()) + .build(); + + ProcessCodegen codegen = ProcessCodegen.ofCollectedResources( + context, + CollectedResourceProducer.fromFiles(BASE_PATH, bpmnFile.toFile())); + + assertThatCode(() -> { + Collection<GeneratedFile> generatedFiles = codegen.generate(); + assertThat(generatedFiles).isNotEmpty(); + }).as("Code generation of a large BPMN with so many nodes must not throw a 'code too large' error") + .doesNotThrowAnyException(); Review Comment: `ProcessCodegen.generate()` only produces `GeneratedFile` source text; it does not invoke a Java compiler, so this test would also pass with the original oversized `process()` method and cannot catch the reported `KieMemoryCompilerException`. Compile the generated sources (and assert an empty compilation error set) so this is an actual regression test for the 64 KB failure. ########## kogito-jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java: ########## @@ -230,7 +247,24 @@ private <U extends org.kie.api.definition.process.Node> void visitNodes(List<U> if (visitor == null) { throw new IllegalStateException("No visitor found for node " + node.getClass().getName()); } - visitor.visitNodeEntryPoint(null, node, body, variableScope, metadata); + + BlockStmt nodeBody = new BlockStmt(); + visitor.visitNodeEntryPoint(null, node, nodeBody, variableScope, metadata); Review Comment: Only top-level nodes are split here. CompositeContextNodeVisitor and ForEachNodeVisitor recursively append every child node and internal connection to this same `nodeBody`, so a large subprocess still generates one oversized `build...` method and can hit the same 64 KB limit. Recursive node generation also needs bounded helper methods rather than being inlined into its parent helper. This issue also appears on line 293 of the same file. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
