Using AI tools like Claude Code to modernize COBOL systems is drawing attention across the tech industry, and the market expects AI to significantly change the economics of legacy migration. The harder problem lies elsewhere: making sure the new system reproduces every behavior of the old one, including processing rules that look trivial but can change the final result.
This guide covers legacy code migration using AI for COBOL and legacy Java: which strategy to pick, which tools fit, where AI translation breaks, and how to validate before cutover.
TL;DR
- AI is an accelerator, not a replacement. Plan for 40–60% effort reduction, not "zero manual intervention".
- COBOL and legacy Java are different problems and need different tools.
- Choose Refactor, Reimagine or Incremental Upgrade before choosing a tool.
- The real investment is equivalence validation, not code generation.
What Is Legacy Code Migration Using AI?
Legacy code migration using AI is the use of large language models and agentic coding tools to translate, refactor or re-architect outdated codebases, typically mainframe COBOL or legacy Java, into modern languages and platforms. AI handles the mechanical translation; humans validate business logic and approve production changes.
The tooling falls into two categories that are not interchangeable. Deterministic tools such as OpenRewrite and ast-grep give the same output for the same input every time, which makes them fast and auditable. Agentic tools such as AWS Transform, GitHub Copilot app modernization and Claude Code handle cases no pre-written recipe anticipated, but their output varies and must be reviewed.

How Accurate Is AI for Legacy Code Translation?
Accuracy drops as system complexity rises, and it is the wrong thing to measure anyway. HCLTech reports that both accuracy and reliability decline as codebases get more tangled. But syntactically valid Java that rounds a cent differently is still a failed migration. The metric that matters is functional equivalence: same inputs, same outputs, including the branches nobody remembers.
That is hard to prove. IBM Research notes that proving two programs equivalent is undecidable in general, and tools like KLEE and CBMC only work within narrow scopes. No vendor can honestly promise a fully verified translation.
What actually improves output: structured context. In HCLTech's pilot, connecting CAST's knowledge graph to the platform over MCP raised accuracy by about 15% on average. The model stopped guessing call chains and data lineage because it could query them.
Realistic savings: 40–60%. Industry analyses put AI-assisted savings at 40–60% of total migration effort, well below the 80% in vendor decks. Translation compresses; validation and cutover do not.
Track these instead of an accuracy percentage:
- Characterization tests passing against the new build
- Output diff rate on production-representative data, with explicit tolerance rules
- Business rules signed off by a domain owner, not just extracted by the model
- Defects found before cutover versus after
COBOL vs Legacy Java: Two Different Migration Problems
COBOL's risk is hidden behavior; legacy Java's risk is dependency entropy. The tool that handles one well often struggles with the other.
| Dimension | COBOL on mainframe | Legacy Java (6/7/8) |
|---|---|---|
| Main risk | Implicit behavior: packed decimals, truncating MOVE, PERFORM THRU, CICS state | Dependency hell: EJB 2, Struts 1, raw JDBC, javax namespace, dead JARs |
| AI does well | Translating single paragraphs and COPY books when given context | Pattern refactoring (EJB → Spring Boot), JDK upgrades, deprecated API replacement |
| AI fails | Rules hidden in nested IF/PERFORM, DFSORT/SyncSort, VSAM/IMS access | Custom frameworks, deep dependency graphs, JVM-specific behavior |
| Best tools | AWS Transform for mainframe, IBM watsonx Code Assistant for Z | OpenRewrite for mechanical changes + an agentic tool for patterns |
| Validation | Golden-master tests, byte-level output diff, parallel run | Generated unit tests, API contract checks, behavioral equivalence |
COBOL programs can run 10,000 lines with no functions, sharing data definitions through COPY books and depending on CICS, VSAM and JCL. Models trained mostly on GitHub code rarely see this, so they get the syntax right and the semantics wrong.
Legacy Java is readable to AI; the work is replacing whole architectural layers. EJB 2 beans become Spring services, Struts actions become controllers, raw JDBC becomes JPA, and javax becomes jakarta, often with third-party libraries that never made the switch.
Choose Your Strategy Before You Choose a Tool
Picking a tool before a strategy is the most common reason AI migration projects stall. Three strategies dominate in 2026:
| Strategy | What it means | AI's role | Best for |
|---|---|---|---|
| Refactor | New language, same architecture (COBOL monolith → Java monolith) | Agentic translation of business logic, deterministic syntax conversion | Stable logic; pain is mainframe cost or lack of COBOL talent |
| Reimagine | Rebuild as services or event-driven components | Extract business rules, propose service boundaries, scaffold new code | Monoliths that block the business, teams ready for distributed-system overhead |
| Incremental Upgrade | Modernize Java in place (Java 8 → 17/21, old Spring → Spring Boot 3) | Mostly deterministic recipes; agents for leftover patterns | Sound apps with security, performance or cloud-readiness problems |

Avoid the JOBOL trap. JOBOL is Java that compiles but is still COBOL in structure: global static fields mimicking WORKING-STORAGE, 2,000-line methods mirroring paragraphs, no dependency injection. It happens when Refactor output goes straight to the repository. Treat AI output as a draft and make an idiomatic refactoring phase mandatory.
AI Tools for Legacy Code Migration in 2026
No single tool handles a full migration; judge each by how it fits your strategy and deployment constraints.
| Tool | Best for | Type | Deployment | Pricing | Caveat |
|---|---|---|---|---|---|
| IBM watsonx Code Assistant for Z | COBOL → Java on IBM Z | Agentic | On-prem / IBM Cloud | Enterprise subscription | Complex logic still needs heavy human validation |
| AWS Transform for mainframe | Large-scale COBOL/PL/I → Java (Refactor or Reimagine) | Agentic | AWS | Pay-as-you-go | AWS lock-in; CICS/VSAM mapping takes setup |
| AWS Transform custom | Java 8 → 17/21 at enterprise scale | Agentic | AWS | Pay-as-you-go | Less predictable on huge monoliths without recipes |
| GitHub Copilot app modernization | JDK and Spring Boot upgrades in the IDE | Agentic (OpenRewrite under the hood) | VS Code, IntelliJ | Per user | Developer-led, not full-codebase translation |
| OpenRewrite / Moderne | Mechanical Java changes: javax → jakarta, dependency bumps | Deterministic | CLI / CI | Free or Moderne SaaS | No semantic translation; needs recipes |
| Claude Code, Cursor | Module refactoring, characterization tests, diff scripts | Agentic | Local / cloud | Per user | Hallucination risk; keep scope small |
A hybrid pipeline works best. Run deterministic recipes first for mechanical changes. Send only the logic recipes cannot handle to agentic tools. Use general coding agents to write characterization tests and comparison scripts, not core migration logic.
Two rules apply to every tool. Pin your target dependencies so agents cannot import libraries that do not exist. And never paste proprietary code into consumer chatbots; use enterprise instances with contractual no-training terms.
A 6-Phase AI Migration Workflow
A migration is a gated pipeline, not a single translation run; skipping the early phases is why pilots fail to scale.
- Readiness and context. Map dependencies, measure existing test coverage and list critical business rules. Build a knowledge graph (CAST or custom parsers) to feed the AI later. Output: dependency map, coverage baseline, prioritized rule list.
- Discovery and rule extraction. Parse code into ASTs with Tree-sitter or ANTLR, then use an LLM to extract rules and data flows. A domain owner signs off every rule. Output: validated functional spec.
- Granular translation. Translate one COBOL paragraph or Java method at a time, retrieving outside context through a knowledge graph or MCP server instead of pasting whole files. Correct logic beats clean code here. Output: equivalent modules with unit tests.
- Idiomatic refactoring. Senior engineers remove JOBOL: split large methods, add dependency injection, replace deprecated APIs. Output: maintainable code ready to integrate.
- Equivalence validation. Nothing advances without passing the three test layers below. Output: report with zero critical discrepancies.
- Cutover. Use the strangler fig pattern: move one function at a time to the new system, starting with low-risk flows, while the old one keeps running. A tested rollback plan is mandatory. Output: phased rollout.
Code Examples: Where AI Gets It Wrong
AI maps syntax well and semantics poorly; these three errors compile cleanly and fail in production.
1. COMP-3 arithmetic: truncation, not rounding
05 WS-QTY PIC S9(5) COMP-3. 05 WS-PRICE PIC S9(5)V999 COMP-3. 05 WS-TOTAL PIC S9(7)V99 COMP-3. COMPUTE WS-TOTAL = WS-QTY * WS-PRICE.
A naive translation uses double, often followed by Math.round:
double total = Math.round(qty * price * 100) / 100.0;
Without the ROUNDED phrase, COBOL truncates extra decimals. double adds binary precision errors, and Math.round rounds instead of truncating. The totals drift by a cent and break reconciliation at month-end.
BigDecimal total = qty.multiply(price).setScale(2, RoundingMode.DOWN); // If the COBOL uses ROUNDED, use RoundingMode.HALF_UP instead
Set a project-wide type-mapping rule (COMP-3 → BigDecimal, rounding mode per statement) rather than fixing this case by case.
2. PERFORM THRU runs every paragraph in between
PERFORM 100-VALIDATE THRU 300-TOTAL. ... 100-VALIDATE. ... 200-APPLY-DISCOUNT. ... 300-TOTAL. ...
AI often reads this as two calls, validate(); total();, and silently drops 200-APPLY-DISCOUNT. PERFORM THRU executes every paragraph physically between the two names.
validate(); applyDiscount(); total();
If the range contains GO TO statements, merge the paragraphs into one method to preserve the exact control flow.
3. EJB 2 session bean → Spring Boot
A naive translation adds modern annotations but keeps the old plumbing:
import javax.ejb.Stateless;
@Stateless
public class OrderServiceBean implements OrderServiceRemote {
public void process(Order order) throws RemoteException {
AuditService audit = (AuditService) new InitialContext()
.lookup("java:comp/env/ejb/Audit");
audit.log(order);
}
}
The javax namespace is replaced by jakarta, and JNDI lookups fail in a standard Spring Boot runtime.
@Service
public class OrderService {
private final AuditService auditService;
public OrderService(AuditService auditService) {
this.auditService = auditService;
}
public void process(Order order) {
auditService.log(order);
}
}
Testing: Proving the New Code Behaves the Same
You must build the validation harness yourself, because the legacy system rarely has one. Most COBOL systems have no automated tests, and many legacy Java monoliths sit below 20% coverage. A module is ready for cutover only after it passes three layers:
- Characterization tests (golden master). Before changing code, run production-representative data through the legacy system and record every output and state change. The new code must match that record exactly. For unit-level coverage, IBM Research uses symbolic execution to generate COBOL tests with mocked external calls, then generates equivalent JUnit tests for the Java version.
- Property-based tests. Use jqwik (Java) or Hypothesis (Python) to throw thousands of random boundary inputs at rules that must always hold, such as "line items always sum to the header total". The framework shrinks any failure to the minimal failing input.
- Parallel run. Send the same live or historical traffic to both systems and diff outputs byte by byte. Define tolerances up front (for example, timestamp formats), treat any difference in calculations or records as a stop, and compare latency too: AI often translates naively, such as a database query inside a loop.

Cost & Timeline
AI makes translation cheap; it does not make migration cheap. Three pricing models are common:
- Per agent-minute. AWS Transform has been reported at about $0.035 per agent-minute; one published test upgraded a ~17,000-line Java app in about 72 minutes, roughly $2.52 in tooling.
- Per line of code. Still used by traditional modernization vendors, at lower rates than manual rewrites.
- Time & materials. The norm for hybrid migrations, covering pipeline setup, validation and cutover.
The tooling bill is a small fraction of the budget. Validation, parallel runs and cutover usually take the largest share. A 100,000-line COBOL-to-Java project still takes months, set by business-rule complexity and validation strictness rather than generation speed.
Frequently Asked Questions
Can AI fully translate COBOL to Java automatically?
No. AI translates syntax and proposes structure, but it cannot guarantee semantic equivalence for complex business logic. Human review, characterization testing and a refactoring phase remain mandatory before anything reaches production.
How accurate is AI code translation?
There is no reliable single percentage, and accuracy falls as complexity rises. The metric that matters is functional equivalence: does the new code produce the same outputs as the old code for the same inputs, including edge cases?
How long does an AI-assisted migration take?
AI typically cuts total effort by 40–60% compared with a manual rewrite, but a 100,000-line COBOL-to-Java project still takes months. Business-rule complexity and validation requirements set the timeline, not generation speed.
What is JOBOL and how do you avoid it?
JOBOL is Java that compiles but keeps COBOL's structure: huge methods, global state, no dependency injection. Avoid it with a mandatory refactoring phase where engineers restructure the AI's raw translation into idiomatic code.
Should we refactor or reimagine our mainframe?
Refactor if the goal is leaving the mainframe while keeping stable business logic. Reimagine only if the monolith actively blocks the business and your team is ready to run distributed services.
Readiness Checklist and How Haposoft Can Help
Before starting, you should be able to answer yes to all five:
- ☐ We have chosen Refactor, Reimagine or Incremental Upgrade.
- ☐ We can record a golden master of current system behavior.
- ☐ A staging environment mirrors production for parallel runs.
- ☐ Senior engineers are assigned to review AI output.
- ☐ Budget covers validation and a tested rollback plan, not just translation.
The migrations that succeed rely on structured context and rigorous equivalence validation, not raw code generation. That is how Haposoft's AI Legacy Migration service works, end to end:
- Assessment and discovery: dependency mapping, business-rule extraction and a migration readiness review.
- Custom MCP pipelines: give AI the exact system knowledge it needs, from call graphs and COPY books to data lineage.
- AI-assisted translation and refactoring: COBOL to Java and Java 8 to 17/21, with senior engineers turning raw output into idiomatic code.
- Automated equivalence validation: golden-master tests, property-based tests and parallel runs that prove the new code behaves like the old.
- Phased cutover: strangler fig rollout with a tested rollback plan.
Contact Haposoft to discuss your legacy modernization architecture and schedule a technical assessment.

