fix(parse_file): handle EnumDeclaration and AnnotationDeclaration in get_classes_and_methods#19
Merged
Conversation
…get_classes_and_methods
sheilaliuxl
reviewed
May 20, 2026
|
|
||
| CLASS = "class" | ||
| INTERFACE = "interface" | ||
| ENUM = "enum" |
Contributor
There was a problem hiding this comment.
nit: They're sorted
Otherwise LGTM
Contributor
Author
There was a problem hiding this comment.
@sheilaliuxl thanks! should be fixed now!
sheilaliuxl
reviewed
May 20, 2026
sheilaliuxl
approved these changes
May 21, 2026
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.
Summary
parse_file.get_classes_and_methodsonly setscurrent_classwhen it encountersClassDeclarationorInterfaceDeclaration. Top-level enums and annotations fall through, so when the AST traversal reaches a method nested inside an enum constant's anonymous body,current_class is Noneand the function raises:This crashes
same_classes_and_methods(and any caller ofget_classes_and_methods) on otherwise-valid Java sources.Repos affected
Three repos in
AmazonScience/migration-bench-java-fulldeterministically hit this crash during reward evaluation (8/8 rollouts each in one training step):thomasmueller/tinyStats— top-level enum with abstract method overridden in each constant's anonymous body (the canonical reproducer).justauth/JustAuth— same shape, different method name (authorize).orphan-oss/ognl— same shape, different method name (getValue).Fix
Add
EnumDeclarationandAnnotationDeclarationto the dispatch inget_classes_and_methods, alongside two new module-level constantsENUMandANNOTATION(mirroring the existingCLASS/INTERFACEpair):same_classes_and_methodscompares the same file pre/post-migration, so the new tuple types align on both sides — no change required there.Tests
Added two fixtures and two parametrized cases covering the new shapes:
testdata/Status.java— top-level enum with constants overriding an abstractmethod (matches the
tinyStatsshape that triggered the original crash).testdata/Marker.java— top-level@interfacewith a method element.The new cases are appended to the existing
@parameterized.expandblock ontest_get_classes_and_methodsand assert the expected tuple sequences:Status.java→(("enum", "Status"), ("method", ("describe", False)), ...)Marker.java→(("annotation", "Marker"),)Local run:
python -m unittest migration_bench.lang.java.eval.test_parse_file -v— 19/19 pass (5 pre-existingget_classes_and_methodscases + 2 new + 12 unrelated).End-to-end validation
Beyond unit tests, validated using a vLLM-served Qwen3-Coder-30B as the migration agent:
thomasmueller/tinyStatsrollout: pre-fix the reward function raisedValueError: Unable to find out class for method describeand the rollout errored out. Post-fix, the same repo runs end-to-end and produces a numeric reward (reward=1.0, build + test equivalence both pass) — the agent's full migration was successfully scored for the first time.JustAuth,ognl) no longer crash; they now flow through the reward function normally and either succeed or fail on legitimate migration criteria.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.