ARTICLE AD BOX
I'm facing an issue with JasperReports after recompiling a template. Here's the situation:
In 2022, I created a PDF template using JasperReports Studio (I believe it was version 6.20) and compiled it successfully. The compiled .jasper file worked perfectly with my existing Java project, which uses an older set of JasperReports libraries (specifically jasperreports-2.0.4.jar and other dependencies listed below). The old template still works fine – I can fill it and generate PDFs without any errors.
Recently, I needed to modify the template. I used the same version of JasperReports Studio (still version 6.20, as far as I know) to open and recompile the template without making any changes. However, when I replaced the old .jasper file with the newly compiled one in my project, the code started throwing errors (see screenshot/stack trace below).
My project dependencies (Maven-style, but using system scope) are:
<dependency> <groupId>localjars1</groupId> <artifactId>ireportjars</artifactId> <version>1.0.1</version> <scope>system</scope> <systemPath>${project.basedir}/lib/commons-digester-1.7.jar</systemPath> </dependency> <dependency> <groupId>localjars2</groupId> <artifactId>ireportjars</artifactId> <version>1.0.2</version> <scope>system</scope> <systemPath>${project.basedir}/lib/itext-1.2.3.jar</systemPath> </dependency> <dependency> <groupId>localjars3</groupId> <artifactId>ireportjars</artifactId> <version>1.0.3</version> <scope>system</scope> <systemPath>${project.basedir}/lib/iTextAsian.jar</systemPath> </dependency> <dependency> <groupId>localjars4</groupId> <artifactId>ireportjars</artifactId> <version>1.0.4</version> <scope>system</scope> <systemPath>${project.basedir}/lib/jasperreports-2.0.4.jar</systemPath> </dependency>JDK version: 1.8
The error occurs at runtime when the Java code attempts to fill the report. Here's the stack trace (or error message):
java.lang.NullPointerException: null at net.sf.jasperreports.engine.JRPropertiesMap.readObject(JRPropertiesMap.java:185) 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 java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1185) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2345) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2236) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1692) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2454) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2378) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2236) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1692) at java.io.ObjectInputStream.readArray(ObjectInputStream.java:2142) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1680) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2454) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2378) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2236) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1692) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2454) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2378) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2236) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1692) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:508) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:466) at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:192) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:580) at org.springblade.common.utils.PrintUtil.GenPDF(PrintUtil.java:186) at org.springblade.common.utils.PrintUtil.TSGenDownPDF(PrintUtil.java:195) at org.springblade.modules.tender.controller.TendProjectMaterialController.GenZBBytes(TendProjectMaterialController.java:2877) at org.springblade.modules.tender.controller.TendProjectMaterialController.GenDownPDFOne(TendProjectMaterialController.java:2676) at org.springblade.modules.tender.controller.TendProjectMaterialController$$FastClassBySpringCGLIB$$7a88e6a9.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)What I've tried:
I ensured that I'm using the exact same version of JasperReports Studio as before (though I'm not 100% sure about the version number – it might be 6.20, but the project uses very old libraries).
I compared the old and new .jasper files and noticed differences (likely due to different JasperReports library versions used during compilation). The old file is about [size] KB and the new one is [size] KB.
I also confirmed that if I put back the original .jasper file (compiled in 2022), everything works perfectly. So the issue is definitely with the newly compiled version.
Additional information:
The original working .jasper file (the one that still fills correctly) is available here:
https://drive.google.com/file/d/1uk-ZiAy-DuEvsEV1AxpgM20c2yCKcpSi/view?usp=sharing
I've attached the old JRXML template (the one that works) for reference. Below is a snippet of its key properties (e.g., language, page size, import statements) – the full file is available [here if I can provide a link, or as an attachment in the post if supported]. The template uses simple elements like text fields and static text, and does not involve any custom scripts or complex expressions.
My question:
How can I recompile the JRXML template so that it remains compatible with the old jasperreports-2.0.4.jar library used in my project? Do I need to configure JasperReports Studio to compile for an older version of JasperReports, or should I consider upgrading the project's JasperReports dependency? If upgrading is the only solution, what would be the minimal compatible version that works with JDK 8 and my existing dependencies?
Any guidance would be greatly appreciated. Thank you!
