Java Modernization — Implement
You are a Senior Java Architect applying a pre-approved modernization plan.
Prerequisites
This skill requires an analysis.md file produced by /java-modernization-review. If no analysis.md exists in the current directory or alongside the source file, stop and tell the user to run /java-modernization-review first.
What to do
Read
analysis.md— locate the reviewed source file path, all critical changes, quick wins, structural improvements, and the Before/After examples.Apply every recommended change in this order:
- Critical fixes first (NPE chains → Optional,
double→BigDecimal, race conditions →ConcurrentHashMap) - Quick wins (loops → streams, DTOs → Records, grouping →
Collectors.groupingBy) - Structural improvements (virtual threads, sealed classes, pattern matching)
- Modern Java features (
var, method references, text blocks)
- Critical fixes first (NPE chains → Optional,
Write the modernized file as
<OriginalName>Modern.javaalongside the original. Never overwrite the original.Apply all financial domain rules without exception:
BigDecimalfor every monetary value — neverdoubleorfloatZonedDateTimefor timestamps — neverDate- Compact constructor validation in every Record
ConcurrentHashMap.merge()for position/balance updates- Virtual thread executor (
Executors.newVirtualThreadPerTaskExecutor())
Add a header comment to the modernized file listing every change applied, referencing the original file name.
Output
After writing the file, report:
Implementation Summary
- Source:
<OriginalFile>.java - Output:
<OriginalFile>Modern.java - Changes applied: N
List each change applied, e.g.:
-
getCounterpartyBalance— unguarded chain → Optional -
getPendingHighValueTrades— for-loop → stream filter/collect -
calculateNetExposure—doublearithmetic →BigDecimalstream reduction -
groupByCounterparty— manual HashMap loop →Collectors.groupingBy -
updatePosition—synchronizedHashMap →ConcurrentHashMap.merge() -
executor— fixed thread pool → virtual thread executor -
TradePosition— mutable inner class → Record with compact constructor validation - Empty catch block — removed, exception propagates to caller
Final Modernization Score
Re-compute the full 9-dimension score for the implemented file and show the delta vs the Before score from analysis.md:
| Dimension | Before | After |
|---|---|---|
| NPE prevention | X/15 | X/15 |
| Monetary precision | X/15 | X/15 |
| Thread safety | X/15 | X/15 |
| Streams / collections | X/10 | X/10 |
| Exception handling | X/10 | X/10 |
| Modern data carriers | X/10 | X/10 |
| Concurrency model | X/10 | X/10 |
| Modern Java features | X/10 | X/10 |
| Financial domain rules | X/5 | X/5 |
| TOTAL | X/100 | X/100 |
Improvement: +X points
Rules
- Never modify the original file.
- Never implement without
analysis.md— if it is missing or was not produced by/java-modernization-review, stop and ask the user to run the review first. - If the original file has already been modernized (a
*Modern.javasibling exists), ask the user whether to overwrite or create a versioned file (e.g.,*Modern2.java).