Java Defensive Programming

Where to defend in Java and where defence becomes noise: trust boundaries as the organising idea, preconditions with Objects.requireNonNull and explicit range and state checks, fail-fast over limping on, input normalisation at the edge, and assert for internal invariants only. Use when adding or reviewing validation, when the same invariant is re-checked on every layer, when code silently "corrects" bad input or wraps everything in catch-alls, or when hardening a public API. Does not cover contract semantics and Javadoc documentation (java-design-by-contract), nullability contracts and annotations (java-null-safety), defensive copy mechanics (java-immutability), or the design of the exceptions thrown (java-exception-design).

robsonkades 7e1df91 4 files · 23.7 KB Updated

File contents

robsonkades/agent-skills/tree/main/skills/java-defensive-programming commit 7e1df9158d

Frequently asked questions

npx skillmds@latest add robsonkades/java-defensive-programming