Closeable ContentSigner#822
Conversation
- Updated interface ContentSigner to extend AutoCloseable - Implemented close() method in several anonymous classes that implement ContentSigner
|
I'm not sure... was there a specific reason you did not suggest changing the return for getOutputStream()? |
|
Do you mean changing the return type of |
|
Actually, I finally realised how this didn't work, although I can see why it might give the impression that it does. The idea I guess is to do something like this: The problem is out.close() which should be called before getSignature(), ends up being called after getSignature(), which is too late. The convention in the APIs the calling out.close() is the equivalent of doFinal(), skipping that will mostly work for signatures at the moment (we probably should have enforced it...), but it's possible with some of the newer algorithms which require processing the data twice we may find ourselves in the situation where we have to take advantage of the signal from close(). Closing this as an interesting idea, but possibly a dangerous one. |
ContentSignerobjects hold an output stream that may need to be closed to prevent resource leaks. A caller can get the stream by callinggetOutputStream()method, and close it once the work is done. However, it may be easy to forget to do that.If
ContentSignerextendedAutoCloseable:ContentSigner.close()is not calledUpdating
ContentSignerto extendAutoCloseableis definitely an update in the public API. That may potentially result to compilation errors in client apps. Those errors should be easy to fix thought. Moreover, those errors may make developers look at and fix possible resource leaks in their code.Here is a summary of the update:
ContentSignerto extendAutoCloseable.close()method in several anonymous classes that implementContentSigner.