Abstract
Large language models (LLMs) have demonstrated remarkable proficiency in handling a wide range of tasks within the software engineering domain, but their ability to perform code migration—adapting code to different environments—remains underexplored. In this work, we propose a novel benchmark, CODEMENV: Code Migration Across Environment, designed to evaluate LLMs’ performance in handling code migration tasks. The benchmark comprises 922 data points across 19 Python and Java packages, offering three tasks to systematically evaluate code migration: identifying version-incompatible functions, determining function changes, and adapting code to target environments. Experimental evaluation across seven LLMs revealed an average pass@1 rate of 26.50%, with GPT-4o performing best at 43.84%. We highlight our key findings as follows: (i) LLMs are more familiar with newer function versions, making them better at migrating legacy code, and (ii) a logical inconsistency where LLMs sometimes identify irrelevant function changes for the target migration environment.
Introduction: The Migration Maze
Software libraries are in a constant state of flux. APIs are deprecated, submodules are reorganized, and function signatures change. For developers, this creates a "dependency hell" where code that worked yesterday breaks today because of a library update. While LLMs have proven exceptional at generating code from scratch or translating between languages, their ability to perform code migration—adapting code to run in a different version of the same environment—remains largely unmapped.
This is a critical gap; if LLMs could automate the tedious process of fixing version-related compatibility issues, it would drastically reduce the manual effort required for environment setup and legacy system maintenance.
The CODEMENV Benchmark
To address this, we introduce CODEMENV (Code Migration Across Environment), a benchmark that breaks the migration process into three distinct tasks designed to evaluate different facets of a model's understanding:
- Locating Version-Incompatible Functions: Identifying exactly which lines of code will break in the target environment.
- Answering Function Changes: Explaining what changed (e.g., was the function renamed, deprecated, or did its parameters change?) and in which version the change occurred.
- Code Migration: Actually rewriting the code to ensure it runs correctly in the target environment.
The benchmark consists of 922 examples spanning 11 Python packages and 8 Java packages. It includes both "Easy" levels (one incompatible function) and "Hard" levels (multiple interdependent incompatible functions), covering both OLD2NEW (upgrading legacy code) and NEW2OLD (adapting modern code for older environments) migration directions.
Key Insights and Results
Our evaluation of seven major LLMs reveals several critical findings regarding their current capabilities and limitations in code migration:
- Top Performance and Averages: GPT-4o achieved the highest score on the migration task with a 43.84% pass@1 rate. However, the average success rate across all tested models was only 26.50%, indicating that code migration remains a significant challenge for current AI.
- The "Forward-Looking" Bias: LLMs are significantly better at OLD2NEW migration than the reverse. In the OLD2NEW scenario, the average success rate was 33.56% on easy sets, but this plummeted to 12.77% for NEW2OLD migrations. This suggests models are more familiar with newer function versions, likely due to their presence in more recent training data.
- Version Hallucinations and Logical Inconsistencies: Models often struggle to maintain precise "temporal boundaries" of API evolution. For example, when migrating code between specific versions, a model might mistakenly reference a change that occurred in a completely different version.
- Identification vs. Execution: While models are relatively good at Task 1 (identifying problematic functions), they frequently fail Tasks 2 and 3. The most common failure was a
CallError, where the model correctly identified a problem but still generated code that called an incompatible function anyway. - The Complexity Wall: Performance drops off a cliff when multiple incompatible functions are present in the same snippet, suggesting a lack of deep reasoning required for cascading version conflicts.
Conclusion and Future Directions
CODEMENV highlights a critical need for "temporal awareness" in future CodeLLMs. Current models treat code as a static snapshot rather than an evolving entity. Future work should focus on expanding the benchmark to more languages and libraries and exploring specialized training on versioned documentation to help models understand the chronological flow of software evolution. Automating these migrations could drastically reduce the technical debt and maintenance burden in modern software engineering.
Summary updated