"Defensive programming" is making sure that programs not only have minimal number of errors, but also that missusing the software in the new code will be detected immediately.
For longer definition see: Defensive programming - Wikipedia.org
Generic introductory resources
- Defensive Programming: Being Just-Enough Paranoid - Jim Bird, 2012
- Java Tips and Best practices to avoid NullPointerException - null-safe programming
- Remove The Fluff With Google Guava
- Checked versus unchecked exceptions - use pre-condition checking with exception throwing
- Top 10 Useful, Yet Paranoid Java Programming Techniques -
- What is Assertion in Java - Java Assertion Tutorial
Preconditions, Postconditions, Invariants
Part of defensive programming is enforcing pre-conditions & post-conditions for functions, so client code (from user of your code) will not be able to call your functions in the incorrect way. Other related term is called "Design By Contract" (DBC).
- Comparison of Ways to Check Preconditions in Java - Guava vs. Apache Commons vs. Spring Framework vs. Plain Java Asserts - Markus Sprunck, 2013
- Preconditions, Postconditions, and Class Invariants
- Preconditions, Postconditions, Invariants : Design by Contract for Java
- assert (built-in) / AssertionError - for private parts of library
- IllegalArgumentException, IllegalStateException (or custom exceptions) - for public parts of library
- Guava's Preconditions
- Apache Commons Lang Validate - part of Apache Commons responsible for pre- and post-condition checking, see Validate JavaDoc
- OVal - declare contracts for functions using annotations
- "Java Coding Guidelines: 75 Recommendations for Reliable and Secure Programs" - by Fred Long / Dhruv Mohindra / Robert C. Seacord / Dean F. Sutherland / David Svoboda, 2013 - see chapter "Defensive programming"
- "The CERT Oracle Secure Coding Standard for Java" - by Fred Long / Dhruv Mohindra / Robert C. Seacord / Dean F. Sutherland / David Svoboda, 2011
- Best practices
- Coding standards