Using Jasper Reports v1.2.3
Steps to Reproduce:
(1) Fill a large jasper report.
(2) Export the report using the JRPdfExporter.
(3) Make sure the exportReport() method fails with an OutOfMemoryError.
Expected Results:
- We expect to see an OutOfMemoryError being thrown.
Actual Results:
- The PdfWriter object throws a RuntimeException. There is no mention of the OutOfMemoryError in the stack trace.
- The OutOfMemoryError is completely suppressed and this makes debugging the error difficult.
- Here is the stack trace:
java.lang.RuntimeException: The name 'MyReference123' has no local destination.
at com.lowagie.text.pdf.PdfWriter.addLocalDestinations(Unknown Source)
at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
at com.lowagie.text.Document.close(Unknown Source)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:473)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:260)
Suggested Solution:
- Refactor the exception handling in the exportReport() method so that if the finally block throws an exception, the method will still propagate the first/original exception instead of the exception from the finally block.
Here is some psuedo-code:
Throwable first = null;
try {
// do the export here.
} catch (Throwable newValue) {
// this is the last of all the catch blocks.
first = newValue;
} finally {
try {
// perform the close() resources here.
} catch (Throwable finallyException) {
if (first != null) {
// propagate the first/original exception
} else {
// propagate the exception from the close() method
}
}
}
Recommended Comments