Version-calibrated Java coding skill. Reads the project's maven.compiler.release or Gradle toolchain, uses only features final in that release (17, 21, 25 LTS and the JDKs between), proves it with javac --release, and applies Effective Java (3rd ed.) as updated for modern Java — records, sealed types, pattern switch, virtual threads, scoped values. Use whenever you write, refactor, modernize, upgrade or review plain Java code — e.g. "write a Java class for…", "clean this up", "make this idiomatic", "upgrade to Java 21/25", "review this before I merge", or pasted Java asking for improvements. Not for framework-specific work (Spring wiring, JPA mappings), test-tool choice, JVM tuning, or Kotlin.
Ships in effective-modern-java. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Write Java that compiles on the project's JDK and that a careful reviewer would approve. You already know Java. This skill covers what models still get wrong: features newer than the project's release, modern features with non-obvious traps, Effective Java advice that newer releases changed, and "best practices" that break callers when applied to existing code.
| Where | What to read |
|---|---|
pom.xml | maven.compiler.release, <release> in maven-compiler-plugin, java.version (Spring Boot parent), maven.compiler.source/target |
build.gradle(.kts) | options.release, java.toolchain.languageVersion, sourceCompatibility |
| Elsewhere | .java-version, .sdkmanrc, .tool-versions, CI setup-java, Dockerfile base image |
Precedence: an explicit release (maven.compiler.release, options.release) wins over the toolchain, which wins over JAVA_HOME. A Gradle toolchain of 21 with options.release = 17 means you write Java 17. Check for --enable-preview in the compiler args. If it's absent, preview features are off-limits, whatever the JDK.
Runtime.version().feature() check.Release gates (final features; this table is the source of truth):
| Release | Usable from here on |
|---|---|
| 17 (LTS) | records, sealed types, instanceof patterns, switch expressions, text blocks, var, Stream.toList(), RandomGenerator, HexFormat |
| 18 | UTF-8 default charset, {@snippet} Javadoc, finalization deprecated for removal |
| 19 | ExecutorService is AutoCloseable; Future.state()/resultNow() |
| 21 (LTS) | pattern switch (when, case null), record patterns, virtual threads, SequencedCollection/Map (getFirst, getLast, reversed), Math.clamp, StringBuilder.repeat |
| 22 | unnamed variables/patterns _, Foreign Function & Memory API |
| 23 | Markdown doc comments /// |
| 24 | stream gatherers (Gatherers.windowFixed/windowSliding/fold/scan/mapConcurrent); synchronized no longer pins virtual threads (JEP 491) |
| 25 (LTS) | ScopedValue, flexible constructor bodies, import module, compact source files + instance main, KDF API |
| 26, 27 | no new language features; HTTP/3 in HttpClient (26) |
| Preview only (through 27) | StructuredTaskScope (final targeted for 28), primitive patterns, StableValue/LazyConstant |
| Never | STR."…" string templates (withdrawn, removed in 23) |
Per-feature notes, JEPs and BAD/GOOD code: references/modern-java.md.
These are for new code. For existing code, Step 3's refactoring rules take precedence. Each default says why, so you can deviate when the reason doesn't apply. When you do, say so.
Types
items = List.copyOf(items)). Override toString when a component is secret. Not for JPA entities, mutable state, or identity types.switch expression with no default, so adding a variant breaks the build everywhere it matters. On 17 there's no pattern switch: put an abstract method on the interface, or use a visitor, to get the same compile-time guarantee. An instanceof chain ending in throw gives no guarantee.EnumMap/EnumSet; never compute with or persist ordinal().BigDecimal built from String/valueOf, with an explicit RoundingMode on every division or rate. A Money record that stores amounts at currency scale must normalize scale in its compact constructor, or the generated equals says 2.0 ≠ 2.00. Use amount.setScale(digits, RoundingMode.UNNECESSARY): it rejects 10.005 USD instead of silently rounding it. Guard Currency.getDefaultFractionDigits() < 0 (XAU, XXX). Unit prices and FX rates that need more precision belong in a separate type.OrderId, Weight), not bare String/double. Inject a Clock where tests need "now".APIs
final or sealed unless designed for extension. Exception: classes a framework must proxy (Spring @Configuration and class-based @Transactional/@Async beans, JPA entities) must stay non-final.null. Optional only as a return type: not fields, parameters or elements, and no bare get(). If the project uses JSpecify, follow its annotations.Errors and resources
e.printStackTrace(), no System.out "handling". Log through the project's logger and recover, or rethrow with the cause attached. An intentionally ignored exception is named ignored (or _ on 22+) and gets a comment explaining why.InterruptedException: propagate it, or call Thread.currentThread().interrupt() before translating it. Never swallow it. For APIs called from request handlers, translating to an unchecked exception after restoring the flag is usually friendlier than a checked throws.AutoCloseable scoped to a method. Long-lived ones, such as a component's executor, close at shutdown.Concurrency
Executors.newVirtualThreadPerTaskExecutor()); never pool them; cap a fragile downstream with a Semaphore.ExecutorService.close() waits for submitted tasks to finish. On 25 that includes tasks invokeAll already cancelled. A per-call try (var ex = …) therefore doesn't bound latency when a callee ignores interrupts, and many HTTP/JDBC clients do. For deadline-bound fan-out, keep a long-lived executor (shut down at exit with shutdownNow() plus a bounded awaitTermination) and use invokeAll(tasks, timeout, unit), which cancels stragglers at the deadline. Don't call f.get(2, SECONDS) in a loop: the worst case is N × 2s. Cancelled-but-uninterruptible calls keep running in the background, so tell the user the client's own connect/read timeouts are what actually bound them.synchronized on virtual threads (it pins the carrier); use ReentrantLock. JDK 24+ fixed this. The runtime JDK decides, not --release.Set.add's return value, putIfAbsent, computeIfAbsent. A ConcurrentHashMap doesn't make if (!m.containsKey(k)) m.put(k, v) safe.ScopedValue (25) replaces ThreadLocal for context passed down a call chain. It is not inherited by tasks you submit to an executor, only by StructuredTaskScope forks, which are preview. Rebind it inside the task if needed. MDC, security and transaction context still live in ThreadLocals today.| Trap | What happens | Do instead |
|---|---|---|
Arrow-form switch statement over an enum | Not checked for exhaustiveness. A missing case compiles and silently does nothing. | Use a switch expression. On 21+, adding case null -> throw … makes the statement exhaustiveness-checked too |
default in a switch over a sealed type or enum you own | Hides new variants from the compiler | Leave default out. For third-party or externally sourced enums, tolerating unknown constants is correct |
| Code compiled against an old sealed hierarchy | New subtype at runtime → MatchException | Recompile dependents; treat new variants as breaking |
Stream.toList() vs Collectors.toList() vs toUnmodifiableList() | toList() is unmodifiable but allows nulls; toUnmodifiableList() throws NPE on null; Collectors.toList() makes no mutability promise | Use toList() only when callers don't mutate; else toCollection(ArrayList::new) |
List.of / List.copyOf / Map.of | Reject null elements; List.of(..).contains(null) throws NPE; Map.of throws on duplicate keys | Filter nulls first or use another collection; toMap(k, v, merge) for duplicates |
Collections.unmodifiableList(list) | A view: later changes to list show through | List.copyOf(list) for a snapshot |
| Record with an array component | equals/hashCode compare the array by reference | Use List, or override both |
list.reversed() (21) | A live view, not a copy | List.copyOf(list.reversed()) for a snapshot |
getFirst() on an empty list | NoSuchElementException | Check isEmpty() |
Optional.orElse(expensive()) | The argument is evaluated even when a value is present | orElseGet(() -> expensive()) |
Integer a == b | Reference comparison; works only for −128..127 | equals, or primitives |
new BigDecimal(0.1) | Captures the binary error (0.1000000000000000055…) | new BigDecimal("0.1") / BigDecimal.valueOf(0.1) |
Shared static SimpleDateFormat | Corrupted output under concurrency | A DateTimeFormatter constant |
One RandomGenerator from RandomGeneratorFactory (e.g. L64X128MixRandom) shared across threads | These algorithms aren't thread-safe | One instance per thread, or ThreadLocalRandom.current() |
javax.xml.bind (JAXB), Nashorn, reflection into java.* internals | Removed from the JDK (11, 15) or blocked since 17: fails at runtime, not always at compile time | Explicit Jakarta/Nashorn dependencies; supported APIs (see modern-java.md#avoid) |
Writing new code. Find the baseline (Step 1). Design the types first, then the behavior. Add tests for the behavior. Then verify (below).
Verify, don't assume. Run the project's build (./mvnw verify, ./gradlew build, or the system mvn/gradle if there's no wrapper). With no build, compile with javac --release <N> -Xlint:all, adding -cp for any dependencies. Use --release, not -source: it also rejects APIs newer than N, such as List.getFirst() under 17. A clean compile at the right release proves Step 1 held.
Refactoring and modernizing existing code. Preserve observable behavior, because that's the contract.
BigDecimal/java.time internally. Records are for new internal types.hashCode, swallowed exceptions, leaks, or null meaning "none". List each one.double → BigDecimal return types, a mutable class → record, Date → Instant in signatures. The usual path is a new method next to a @Deprecated old one.m(Category) beside m(String) breaks m(null).Upgrade order and OpenRewrite recipes: references/modern-java.md#upgrade.
Reviewing.
file:line, the concrete consequence (what breaks, for whom), and the fix. End with the minimum set to fix before merge.EJ 11) only where the reasoning is non-obvious; tagging every line is noise.default.references/modern-java.md: Java 17 → 25 feature guide. JEPs, BAD/GOOD code, preview and withdrawn APIs, and a safe upgrade order. Read it when using any feature newer than Java 11, or when upgrading code.references/effective-java.md: all 90 Effective Java (3rd ed.) items marked Applies / Refined / Superseded, each with its modern note, plus worked before/after examples (tagged class → sealed, value class → record, virtual-thread fan-out with deadlines, and more). Read it when reviewing, or when you need the reasoning behind a default.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/effective-modern-java:effective-modern-javafrom effective-modern-java
npx claudepluginhub adityamparikh/effective-modern-java --plugin effective-modern-java