Use try-with-resources for AutoClosables where feasible
Where unfeasible, this commit adds inline comments to explain why try-with-resources must not be used in certain scenarios. The purpose of the comments is to avoid accidental conversion to try-with-resources at a later date. Closes gh-27823
This commit is contained in:
committed by
Sam Brannen
parent
999376f9f9
commit
e1200f34e7
@@ -169,6 +169,8 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter<B
|
||||
|
||||
ImageInputStream imageInputStream = null;
|
||||
ImageReader imageReader = null;
|
||||
// We cannot use try-with-resources here as, potential, exception upon closing
|
||||
// would still bubble up the stack
|
||||
try {
|
||||
imageInputStream = createImageInputStream(inputMessage.getBody());
|
||||
MediaType contentType = inputMessage.getHeaders().getContentType();
|
||||
|
||||
@@ -131,6 +131,8 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||
|
||||
protected void writeContent(Resource resource, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
// We cannot use try-with-resources here as, potential, exception upon closing
|
||||
// would still bubble up the stack
|
||||
try {
|
||||
InputStream in = resource.getInputStream();
|
||||
try {
|
||||
|
||||
@@ -155,6 +155,8 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
|
||||
responseHeaders.setContentLength(rangeLength);
|
||||
|
||||
InputStream in = region.getResource().getInputStream();
|
||||
// We cannot use try-with-resources here as, potential, exception upon closing
|
||||
// would still bubble up the stack
|
||||
try {
|
||||
StreamUtils.copyRange(in, outputMessage.getBody(), start, end);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user