Introduction
As software engineering evolves, the need to migrate legacy systems—such as transitioning from COBOL to Java—or integrate diverse technology stacks has made automatic code translation a critical objective. However, the reliability of these source-to-source translators (transpilers) remains a significant hurdle. Evaluating these tools is notoriously difficult because traditional metrics often fail to capture semantic correctness. This paper introduces MBTA (Mutation-based Code Translation Analysis), a novel framework designed to stress-test translators by applying tiny syntactic changes to programs and verifying if the translator can maintain semantic equivalence.
The Challenge of Code Translation
Current research primarily relies on two metrics to evaluate translators:
- BLEU Score: This measures syntactic similarity, focusing on how closely the translated text resembles a reference translation. While efficient, it ignores whether the resulting code is functional.
- Computational Accuracy (CA): This checks if the translated program passes the same test cases as the original. Although more robust than BLEU, CA is limited to the specific logic of the input program.
The authors argue that these metrics fail to account for "trustworthiness." A translator might "memorize" common coding patterns, passing CA for a specific program while failing on slight variations. MBTA aims to quantify this gap by testing the translator's ability to handle unseen but logically similar code.
The MBTA Framework
The MBTA workflow consists of three primary steps:
- Mutation: A source program (e.g., in Java) is modified using a mutation tool like $\mu$Java to create "mutants"—versions of the program with a single minor change, such as swapping a
+for a-or changing a>to a>=. - Translation: The translator under test converts both the original program and its mutants into the target language (e.g., Python).
- Analysis: The original mutant and its translated counterpart are executed using the same test inputs.
The core of this framework is the Mutation-based Translation Score (MTS). Unlike traditional mutation testing, which evaluates test suite quality, MTS compares a mutant to its own translation. If the outputs differ, the mutant is "killed," indicating a translation failure. A lower MTS signifies a more robust and trustworthy translator.
Experimental Setup
The study evaluated two prominent translators: TransCoder (a deep-learning model from Meta) and j2py (a rule-based tool). The evaluation utilized:
- GeeksforGeeks Dataset: 612 Java-Python program pairs with valid test suites.
- Mutant Pool: 75,082 mutants generated using 19 different mutation operators.
Key Insights
The Memorization Trap
The research revealed that translators often produce perfect translations for original programs but fail completely when faced with a mutant. This suggests that models frequently rely on memorized templates rather than a deep semantic understanding of program logic.
Operator Sensitivity
Certain code structures proved particularly challenging. For instance, "short-cut" operators like ++ or -- in Java often led to failures. Since Python lacks direct equivalents for these operators within expressions, translators frequently failed to adjust the surrounding logic correctly.
Revealing Hidden Bugs
MBTA successfully exposed bugs that CA missed. For example, a translator might incorrectly map Integer.MIN_VALUE to 0. If standard test cases only use positive numbers, CA remains at 100%. However, a mutant that forces the logic to handle negative values will "kill" the translation, exposing the underlying flaw.
Results and Discussion
The findings indicate a significant "trustworthiness" gap in state-of-the-art tools. Both TransCoder and j2py failed to correctly translate more than 70% of the mutants, with TransCoder and j2py yielding MTS scores of 0.7044 and 0.7064, respectively. Furthermore, for nearly 20% of the programs, TransCoder could not produce a single correct mutant translation, despite often translating the original program perfectly.
The study also found a strong inverse correlation (-0.78) between MTS and CA. This confirms that as basic accuracy drops, trustworthiness also declines, but MTS provides a much more granular view of specific failure points.
Conclusion and Future Work
MBTA provides a "semantic stress test" that reveals the fragility of modern code translators. While the study is currently limited by the available mutation operators and the quality of test suites, it opens new avenues for fault localization—identifying the specific logic within a translator responsible for errors. Future work will expand this analysis to more language pairs, such as C++ to Java, to further enhance the reliability of automated code migration tools.
Summary updated