WW-5733 fix(jasperreports7): stop closing the response stream before the report is written - #1923
Merged
Merged
Conversation
lukaszlenart
marked this pull request as ready for review
September 12, 2026 10:09
…the report is written Every exporter provider obtained the servlet output stream in a try-with-resources block, so the stream was closed as soon as createExporter returned, before JasperReport7Result called exporter.exportReport(). Tomcat commits the response on close with the bytes written so far, which is none, and drops everything written afterwards: every export was an empty 200 with Content-Length: 0. The tests did not notice because Spring's MockHttpServletResponse keeps accepting writes after close. The providers now hand the open stream to the exporter and leave it alone; the result flushes after exporting and the container closes the stream at the end of the request. A response wrapper that refuses writes after close guards the ordering for all six formats. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lukaszlenart
force-pushed
the
WW-5733-stream-close
branch
from
September 12, 2026 10:33
21c3079 to
2397fe1
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes WW-5733
What
Every
JasperReport7*ExporterProvider.createExporterobtained the servlet output stream in a try-with-resources block, so the stream was closed as soon as the method returned — beforeJasperReport7Result.exportReportcalledexporter.exportReport(). Tomcat commits the response onclose()with the bytes written so far (none) and discards everything written afterwards, so every export from this plugin was an empty200withContent-Length: 0— CSV, PDF, HTML, RTF, XML and XLSX alike, since 7.1.0. The unit tests never noticed because Spring'sMockHttpServletResponsekeeps accepting writes afterclose().Reproduced on embedded Tomcat 10.1.34 with a servlet doing the same sequence (close in try-with-resources → write → flush):
status=200 content-length=0 body=0 bytes; the same servlet without the close delivers the payload.Fix
The six providers now hand the open stream to the exporter and leave it alone.
JasperReport7Resultstill flushes after exporting; the container closes the stream at the end of the request, which is the normal servlet idiom. JasperReports'OutputStream-based exporter outputs do not close the stream either (toClose = false), so there is no double close. The 6.x plugin is unaffected — it buffers into aByteArrayOutputStreamand closes after writing.Test
testExportWritesNothingAfterClosingTheResponseStreamruns the result for all six formats against anHttpServletResponseWrapperwhoseServletOutputStreamrejects writes afterclose()— the container semantics the mock lacks. Before the fix it fails on the first format withIOException: Stream closed.🤖 Generated with Claude Code