Missing cleanup contract (ARCH4082)
Key java.performance.dispose-pattern · Severity warning · Category performance
If a class holds an AutoCloseable field but does not itself implement AutoCloseable, there is no way to release the resource it owns, so it leaks.
Incorrect
Section titled “Incorrect”public class Repository { private final Connection conn = openConnection(); // no way to close conn}Correct
Section titled “Correct”public class Repository implements AutoCloseable { private final Connection conn = openConnection();
@Override public void close() throws SQLException { conn.close(); }}Implement AutoCloseable on classes owning closeable fields and close those fields in close().