fix(java): derive filename from class name - #120
Open
aiueokakikukeko18071999 wants to merge 1 commit into
Open
Conversation
Java requires the filename to match the public class name. The hardcoded Code.java caused compilation errors for any code declaring a differently named public class, which is the conventional way to write Java and what LLM-generated code almost always produces. The class name is now extracted from the source and used for both the filename and the java invocation, falling back to Code when no class declaration is found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Java requires the filename to match the public class name. The hardcoded
Code.javacaused compilation errors for any code declaring a differently named public class:Since
public class HelloWorldis the conventional way to write Java, and LLM-generated code almost always uses a descriptive class name, this made the Java runtime effectively unusable unless the model was explicitly instructed to name its classCode.The class name is now extracted from the source and used for both the filename and the
javainvocation, falling back toCodewhen no class declaration is found.No new dependencies.
reis from the standard library.Type of change
How Has This Been Tested?
Tested on arm64 (Ubuntu 24.04, OCI Ampere A1) against a locally built image.
Request:
{"code": "public class HelloWorld { public static void main(String[] args) { System.out.println(\"Hello, World!\"); } }", "lang": "java"}Response:
{"stdout": "Hello, World!\n", "stderr": "", "files": ["HelloWorld.class", "HelloWorld.java"]}tests/unitpasses: 514 passed, 5 skippedblack --checkandflake8 --select=Fpass on the modified fileChecklist: