I have a java class that holds a Closeable resource internally. This means my class also implements the Closeable interface and closes the internal resource in its own close() method.
What is the expected behavior of my class after it has been closed, and generally any closed object in Java? I see the object in a defunct state, where its internals are closed but clients still have a reference to it. IMO accessing it is a programming error, but bugs happen time to time so the behavior should be reasonable even in this case...
Should I?
- throw an exception on all method calls like: IllegalState
- close my eyes like nothing happened and let exceptions through from the close resource?
What is the canonical Java way?
close()
to be called more than once without generating an exception. – Fireresistant