agentleFS
isabelle-barpisabelle-barp/agent-brain/skills/stack-java/SKILL.md

stack-java

Skill0 starsChanged 5 months agoApache-2.0View on GitHub

Java/JVM language, build, and testing patterns for agents working in projects whose docs/TECH_STACK.md lists java. Framework-agnostic core — load alongside the framework overlay (e.g. stack-quarkus) when implementing, testing, or reviewing JVM code.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer constructing a new instance over mutating.

    line 42
  2. Very specific:

    Don't Optional.get() without isPresent.

    line 46
  3. Very specific:

    Never swallow: always chain the cause (throw new DomainX("...", cause)).

    line 50
  4. Distinctive:

    Don't use exceptions for control flow over expected outcomes — model those with a sealed result type (above).

    line 51
  5. Distinctive:

    Mockito sparingly: prefer real collaborators and in-memory implementations of the port interfaces (the abstract-port discipline makes this …

    line 74
  6. Very specific:

    All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md.

    line 104

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Stack: Java (JVM core)

The framework (Quarkus, Spring, plain) is a SEPARATE overlay — this skill is the language/build/test core every JVM project shares. Read the host's docs/ARCHITECTURE.md and docs/TECH_STACK.md for the JDK baseline and framework before assuming APIs (virtual threads, sealed types, and pattern matching gate on the JDK version).

When this applies

Detection markers (any of):

  • docs/TECH_STACK.md ## Detected stacks lists java
  • Build files: pom.xml, build.gradle / build.gradle.kts, settings.gradle*, mvnw / gradlew wrappers
  • Sources: src/main/java/**/*.java, module-info.java
  • Toolchain pins: .sdkmanrc, .java-version, a <maven.compiler.release> / toolchain block

Implementation patterns

These are the patterns this stack commonly uses for an enterprise hexagonal JVM core. Where the host's docs/ARCHITECTURE.md declares different conventions, the host docs win.

Domain modeling — records + sealed hierarchies

// Value object: record gives equals/hashCode/immutability for free.
public record Money(BigDecimal amount, Currency currency) {
    public Money {                                   // compact canonical constructor = the invariant gate
        if (amount.scale() > currency.getDefaultFractionDigits())
            throw new IllegalArgumentException("scale exceeds currency minor units");
        amount = amount.stripTrailingZeros();        // normalize before the field is assigned
    }
}

// Closed domain outcome: sealed permits exhaustive switch with NO default branch.
public sealed interface TransferResult permits Settled, Rejected, Pending {}
  • Records for VOs and immutable DTOs; validate/normalize in the compact constructor — never expose a record that can hold an illegal state.
  • Sealed interfaces/classes for closed sets (domain outcomes, command unions). Switch over them exhaustively with pattern matching and no default — adding a permitted type then becomes a compile error at every call site, which is the point.
  • Entities (identity-based) are NOT records — identity equality is on the ID alone, not all fields. Keep equals/hashCode on the immutable ID only.

Immutability by default

  • Fields final; collections returned as List.copyOf(...) / unmodifiable; defensive-copy mutable inputs (arrays, Date, mutable collections) at the boundary.
  • Prefer constructing a new instance over mutating. A "setter" on a domain object is a smell unless the host docs declare a mutable-entity ORM pattern.

Absence — Optional at boundaries only

  • Optional<T> as a RETURN type for "may be absent" lookups. Never an Optional field, parameter, or collection element (Optional in a collection is an anti-pattern — use an empty collection).
  • Don't Optional.get() without isPresent; use orElseThrow, map, orElseGet. orElse(expensive()) eagerly evaluates — use orElseGet for non-trivial fallbacks.

Error taxonomy

  • Domain errors are unchecked typed exceptions (extends RuntimeException) carrying structured context, mapped to transport codes at the presentation boundary by the framework overlay — domain code never knows HTTP.
  • Never swallow: always chain the cause (throw new DomainX("...", cause)); never catch (Exception e) {}. Catch the narrowest type.
  • Don't use exceptions for control flow over expected outcomes — model those with a sealed result type (above).

Concurrency

  • Immutability first — a shared immutable object needs no lock. Reach for java.util.concurrent (ConcurrentHashMap, Atomic*, BlockingQueue) before synchronized; reach for synchronized/ReentrantLock before hand-rolled wait/notify.
  • Virtual threads (JDK 21+): cheap for blocking I/O fan-out, but synchronized blocks PIN a virtual thread to its carrier — use ReentrantLock on hot paths that run under virtual threads. Do NOT pool virtual threads.
  • ThreadLocal leaks: anything set on a pooled (platform) thread MUST be cleared in finally, or it bleeds into the next task. Audit MDC/security-context propagation across async boundaries explicitly.
  • Publish-safety: a non-final field written by one thread and read by another without a happens-before edge is a data race even if it "works" in tests.

Resource & null discipline

  • try-with-resources for every AutoCloseable (streams, connections, Scope). Never a bare close() in finally.
  • Null-safety via annotations the project already uses (JSpecify / package-info.java @NullMarked); treat parameters non-null by default and validate at the public boundary (Objects.requireNonNull with a message).
  • Streams: no side effects inside lambdas (no mutation of external state, no I/O); they express a transformation, not a loop. For hot/large paths, a plain loop is legitimately faster — don't dogmatically stream.

Persistence — the framework's data module owns the driver (R-PAT-03)

Persistence is a framework concern, not a language one — the repository adapter is built on the framework overlay's first-party data integration, never a hand-managed JDBC Connection/DataSource or raw Mongo client:

  • Spring → Spring Data repositories (spring-boot-starter-data-jpa / spring-data-mongodb): the adapter extends/uses a Spring Data repository interface; Spring owns the EntityManager, the connection pool, and @Transactional binding. Do NOT inject a raw DataSource/JdbcTemplate-by-hand or a bare MongoClient where a Spring Data module covers the store.
  • Quarkus → Panache extensions — see .claude/skills/stack-quarkus/SKILL.md.
  • Plain JVM / no framework → the bare JDBC/driver client IS the integration; keep it isolated in the adapter behind the port.
  • Fallback to a raw driver under a framework is legitimate only for a store the framework has no module for, or hand-tuned SQL the data module cannot express — and it stays inside the adapter, never in domain/application.

Testing on this stack

  • Framework: JUnit 5 (Jupiter) + AssertJ for fluent, descriptive assertions. Parameterized tests (@ParameterizedTest + @MethodSource/@CsvSource) to table-test every boundary value of pure logic — records and sealed-result logic are pure, test them exhaustively.
  • Mockito sparingly: prefer real collaborators and in-memory implementations of the port interfaces (the abstract-port discipline makes this trivial). Mock only true process boundaries you don't own. Never mock value objects or the type under test.
  • Integration: Testcontainers for the real datastore/broker — no in-memory substitutes for the DB (R-TESTI-01: integration tests run real wiring). Reuse a single container per class; don't spin one per method.
  • Determinism: inject the clock (Clock parameter), never Instant.now() in domain code; seed any randomness. Flaky time/concurrency tests are defects, not retries.
  • Assert on behavior and structured error types, not on log strings.

Spec validation checks

Stack-specific checks the spec validators (spec-validate-lead-engineer, on SPEC_<FEATURE>.md §4 API & Domain, §5 Business Rules) delegate here:

CheckSeverity
Closed domain sets modeled as sealed types; switches exhaustive with no default (adding a case is a compile error)BLOCKER
Value objects immutable (records / final fields) and validated at construction — no illegal state representableBLOCKER
Domain errors are typed unchecked exceptions mapped to transport at the boundary; domain has no transport knowledgeBLOCKER
Concurrency/visibility behavior specified for shared state (who wins, what is published-safe)BLOCKER
Optional used only as a return type, never field/param/collection elementWARNING
Absence/error outcomes modeled as result types rather than control-flow exceptions where expectedWARNING
Clock/randomness injected (no ambient now()/random() in domain) so behavior is testableWARNING

Live validation commands

R-VAL-01 matrix (JVM source/test changes) — exact invocations live in docs/DEV_SETUP.md; obligations:

CheckTypical shape (Maven / Gradle)
Compile main + test, fail on warningsmvn -q compile test-compile / gradle compileJava compileTestJava (compiler -Werror where the project sets it)
Run unit + integration tests for affected modulesmvn verify / gradle test integrationTest — the load-bearing row (Testcontainers up)
Static analysis / lint if configuredthe project's checkstyle/spotbugs/errorprone/spotless target per DEV_SETUP
Build the artifactmvn -q package -DskipTests=false / gradle build

All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md. Do not weaken a type, widen a catch, or @Disabled a test to go green — fix the cause.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.