I am having a Problem with Jasper Reports PDF generation in my Java Spring App.
Versions:
Jasper Files built with the jasperreports-gradle-plugin version 0.3.2
<!-- Created with Jaspersoft Studio version 6.11.0.final using JasperReports Library version 6.11.0-0c4056ccaa4d25a5a8c45672d2f764ea3498bebb -->
...
<textField>
<reportElement positionType="Float" x="2" y="161" width="582" height="9" uuid="c39550b8-8786-424e-ae97-54db0f570a05"/>
<box padding="3">
<pen lineWidth="0.5" lineStyle="Solid"/>
</box>
<textElement verticalAlignment="Middle">
<font fontName="Liberation Sans" size="6" isItalic="true" pdfFontName="Helvetica-Oblique" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{String_Input}]]></textFieldExpression>
</textField>
...
When I comment out the above code snippet from my jrxml file it works for all examples I have setup. However when I add this back it works for all except for one, in which case it gives the following stack trace:
SEVERE: Servlet.service() for servlet [orderInvoice] in context with path [/orderInvoice] threw exception [Request processing failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0] with root cause
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at com.lowagie.text.pdf.PdfStructureTreeRoot.nodeProcess(Unknown Source)
at com.lowagie.text.pdf.PdfStructureTreeRoot.nodeProcess(Unknown Source)
at com.lowagie.text.pdf.PdfStructureTreeRoot.nodeProcess(Unknown Source)
at com.lowagie.text.pdf.PdfStructureTreeRoot.buildTree(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.getCatalog(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.close(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:941)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:547)
[exporter.exportReport();]
[buildInvoicePDF(response, result);]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
This does not make sense as something that should happen sometimes, and not all the time. The string that is passed in is hard coded in the code as a way to manage any updates, but this feels more like a configuration issue over a jrxml issue given this bit of code has been stable for over a year, and does not act up in normal changes. I have unified the JasperReport library used to build the jrxml's. I checked each version to try to figure out what is wrong, and could use either a fix or ideas for how to find a fix. I have not found anything on google or any obvious issues.
Thanks
So this was a product of some cleanup I performed on the app in question.
The original designed included some tagging to make the PDF ADA compliant since it used an old version of Jasper Reports. I removed this to resolve some stability issues, but had a new set of stability issues (see question).
The issue was with this bit of code:
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setTagged(true);
This true
is needed to support these added tags, but with them removed this is causing trouble, so this becomes:
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setTagged(false);