Skip to content

use try-with-resources statement in ResourceRegionHttpMessageConverter #35051

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

Conversation

Pankraz76
Copy link

@Pankraz76 Pankraz76 commented Jun 13, 2025

before:

100% (1/1) 66% (10/15) 81% (72/88) 57% (23/40)

now:

100% (1/1) 80% (12/15) 86% (76/88) 65% (26/40)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 13, 2025
@Pankraz76 Pankraz76 force-pushed the fix-ResourceRegionHttpMessageConverter branch from 39e24fc to 746ba02 Compare June 13, 2025 14:55
Copy link
Author

@Pankraz76 Pankraz76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

history is mystery.

}
finally {
try {
in.close();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these is no special handling at all.
we still ignore IO.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -173,19 +173,10 @@ protected void writeResourceRegion(ResourceRegion region, HttpOutputMessage outp
responseHeaders.add("Content-Range", "bytes " + start + '-' + end + '/' + resourceLength);
responseHeaders.setContentLength(rangeLength);

InputStream in = region.getResource().getInputStream();
// We cannot use try-with-resources here for the InputStream, since we have
// custom handling of the close() method in a finally-block.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these is no special handling at all.
we still ignore IO.

@Pankraz76 Pankraz76 marked this pull request as ready for review June 13, 2025 14:56
@Pankraz76 Pankraz76 force-pushed the fix-ResourceRegionHttpMessageConverter branch from 746ba02 to 4373d57 Compare June 13, 2025 20:57
@Pankraz76 Pankraz76 force-pushed the fix-ResourceRegionHttpMessageConverter branch from 4373d57 to b317def Compare June 13, 2025 21:08
print(out, "Content-Range: bytes " +
region.getPosition() + '-' + (region.getPosition() + region.getCount() - 1) +
'/' + resourceLength);
println(out);
println(out);
// Printing content
StreamUtils.copyRange(in, out, start, end);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

details just one hover away:
image

@@ -227,14 +219,14 @@ private void writeResourceRegionCollection(Collection<ResourceRegion> resourceRe
println(out);
}
long resourceLength = region.getResource().contentLength();
end = Math.min(end, resourceLength - inputStreamPosition - 1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min,max,modulo its all used very often from Math of course, as this is the happy path all around.

print(out, "Content-Range: bytes " +
region.getPosition() + '-' + (region.getPosition() + region.getCount() - 1) +
'/' + resourceLength);
println(out);
println(out);
// Printing content
StreamUtils.copyRange(in, out, start, end);
copyRange(in, out, start, end);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its random impl. detail where this comes from we want to copyRange who how or what seems different concern.

// custom handling of the close() method in a finally-block.
try {
StreamUtils.copyRange(in, outputMessage.getBody(), start, end);
try (var in = region.getResource().getInputStream()) {
Copy link
Author

@Pankraz76 Pankraz76 Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could see type as random impl. detail, as well.

image

@Pankraz76 Pankraz76 force-pushed the fix-ResourceRegionHttpMessageConverter branch from b317def to af07e87 Compare June 14, 2025 09:10
@bclozel
Copy link
Member

bclozel commented Jun 14, 2025

Sorry but we cannot process PRs like this. Its title says one thing but the content is all over the place, mixing stylistic changes, new attempts at introducing try-with-resources (and some changing the behavior again), a dozen comments and screenshots.

Please be more considerate of our time and stop submitting similar PRs.

@bclozel bclozel closed this Jun 14, 2025
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 14, 2025
@Pankraz76
Copy link
Author

yes im sorry. will give test for the catch as im interested now. dont understand so tests will help.

can we merge test then at least to improve cover?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants