-
Notifications
You must be signed in to change notification settings - Fork 38.5k
use try-with-resources
statement in ResourceHttpMessageConverter
#35048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use try-with-resources
statement in ResourceHttpMessageConverter
#35048
Conversation
} | ||
catch (FileNotFoundException ex) { | ||
// ignore, see SPR-12999 | ||
catch (Throwable ignored) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch (Throwable ignored) { | |
catch (Throwable | NullPointerException | FileNotFoundException ignored) { |
thats whats going on, right? @bclozel
in.transferTo(out); | ||
out.flush(); | ||
} | ||
catch (NullPointerException ex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NPE is ignored by try-with-resource
.
} | ||
finally { | ||
try { | ||
in.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be called anyways by try-with-resource
.
in.close(); | ||
} | ||
catch (Throwable ex) { | ||
// ignore, see SPR-12999 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we still ignore but in 1 catch not in 3.
first 2 are now handled by try-with-resource
.
Signed-off-by: Vincent Potucek <[email protected]>
07e6101
to
a143254
Compare
@@ -156,5 +156,123 @@ public void writeContentInputStreamThrowingNullPointerException() throws Excepti | |||
|
|||
assertThat(outputMessage.getHeaders().getContentLength()).isEqualTo(0); | |||
} | |||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Test | |
@Test |
checkstyle solution seems broken and costly to obtain such a custom tool not working. better use spot.
@@ -147,31 +145,14 @@ protected boolean supportsRepeatableWrites(Resource resource) { | |||
|
|||
|
|||
protected void writeContent(Resource resource, HttpOutputMessage outputMessage) | |||
throws IOException, HttpMessageNotWritableException { | |||
|
|||
// We cannot use try-with-resources here for the InputStream, since we have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try-with-resources
statement in ResourceHttpMessageConverter
before:
now: