Catalogue / maintainable-java-service-code
maintainable-java-service-code
Older skill: source not recordedSignedReviews Java 17 and later Spring Boot services for clear naming, immutability, type safety, validation, exceptions, logging, and deterministic tests. Use for implementation or code review. Not for enabling preview features, upgrading the toolchain, or deploying a service without approval.--- name: maintainable-java-service-code description: >- Reviews Java 17 and later Spring Boot services for clear naming, immutability, type safety, validation, exceptions, logging, and deterministic tests. Use for implementation or code review. Not for enabling preview features, upgrading the toolchain, or deploying a service without approval. ---
Maintainable Java service code
Inspect the project's Java version, compiler flags, Spring conventions, formatting, and tests before suggesting changes. Java 17 supports records and sealed types, but particular pattern-matching features may require a newer release or preview flags; verify actual compiler support. Obtain explicit human confirmation before writing files, installing dependencies, changing flags, running state-changing tests, contacting services, or deploying.
Keep ownership and types apparent
Use PascalCase for types, camelCase for members/methods, and uppercase underscore-separated names for constants, following existing code. Choose meaningful domain names rather than copying another project's entity vocabulary. Prefer immutable records for value data and final fields for objects; remember records do not make referenced collections deeply immutable. Defensively copy mutable inputs where required.
An Optional return from a lookup expresses absence. Transform with map or flatMap and use an explicit fallback or a meaningful domain exception; do not call get without proving presence. Keep stream pipelines short for transformations and filters, and use a loop when nested streams obscure state or control flow. Check null-handling policy rather than filtering values merely to hide invalid input.
Avoid raw collections and unchecked casts. Bound reusable generic parameters to the behavior they need, such as an identifier contract, without narrowing them unnecessarily. Prefer clear code to clever micro-optimization unless measurements justify the tradeoff.
Make errors and boundaries deliberate
Use domain-specific unchecked exceptions for expected domain failures; wrap technical failures with useful context and preserve the cause. Broad catches belong only at a deliberate central boundary that logs or translates them. Never swallow exceptions. Use parameterized logging through the project's logger, with request or entity references safe to expose; include exception context but redact personal or secret data.
Default to non-null contracts where the supported annotations enforce them. Use Nullable only where absence is intentional, and Bean Validation constraints such as NotNull or NotBlank on appropriate boundary inputs. Validation does not replace resource authorization.
Organize Maven/Gradle source by config, controller, service, repository, domain, DTO, and utility responsibilities when that matches the project; resource configuration is separate, and test packages mirror production where useful. These are user-project locations, not bundled helper files. Keep one public top-level type per file, short focused methods, and consistent two- or four-space indentation. Order constants, fields, constructors, public methods, protected methods, and private helpers unless the repository chooses otherwise.
Replace long parameter lists with coherent DTOs or builders, deep nesting with early exits, unexplained constants with named values, and static mutable state with injected dependencies.
Verify behavior with local tests
Use the project's JUnit 5 and AssertJ conventions and Mockito for explicit dependency mocks where appropriate; avoid partial mocks that hide design problems. Test absence, validation, domain exceptions, collection ownership, and transformation edge cases deterministically, without hidden sleeps or live services. Report actual compile/test results and any unsupported language feature separately.
Never
- Hide failures, share mutable state casually, or rely on unchecked raw types.
- Treat record fields as automatically deeply immutable or enable preview features silently.
- Log credentials or personal payloads, install, write, run consequential commands, or deploy without explicit human confirmation.
| File | Size | SHA-256 |
|---|---|---|
| SKILL.md | 4.2 kB | d0f190de9102 |
| examples.json | 2.2 kB | 7d88ad1ca461 |
Published verbatim from the pinned commit. Nothing is rewritten.
| Version | Pinned commit | Signed | |
|---|---|---|---|
| 1.0.0 Current | Not recorded | 2 Oct 2026 |
Locking a skill to one version needs Pro.