-
Notifications
You must be signed in to change notification settings - Fork 440
Description
(With reference to #337)
Jasper Reports 6.21.4
Windows 11 Pro, 24H2, 26100.2605
OpenJDK Temurin-17.0.13+11 and 21.0.5+11
Since JR version 6.13.0 temporary font files are created in the user's temp directory but are not deleted on exit. This is not a problem on Mac or Linux, only Windows.
I've provided a standalone test case to show this:
The code is this:
import java.io.File;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperReport;
public class JasperTest {
static class ExampleDataSource implements JRDataSource {
@Override
public boolean next() throws JRException {
return false;
}
@Override
public Object getFieldValue(JRField jrField) throws JRException {
return "Test";
}
}
public static void main(String[] args) {
try {
File reportFile = new File("report.jrxml");
JasperReport jrReport = JasperCompileManager.compileReport(reportFile.getAbsolutePath());
JasperFillManager.fillReport(jrReport, null, new ExampleDataSource());
}
catch(JRException ex) {
ex.printStackTrace();
}
}
}- Unzip the attached zip project on Windows
- From the Windows command line run this:
java -cp jasperreports-6.21.4.jar;commons-digester-2.1.jar;commons-logging-1.3.4.jar;commons-collections4-4.4.jar;commons-beanutils-1.10.0.jar JasperTest.java - Note that in the temporary directory (
C:\Users\username\AppData\Local\Temp) that there are two font files of the formjr-font123456789123456789.ttf - Run the example again and note two more font files are created
In our real world use of JR more than two temporary font files are created at a time and remain in the temp folder (around 20) and after a few invocations of JR code there could be thousands.
It seems that font files that are created in AwtFontManager are marked to be deleted on exit:
However, when Java calls its method to delete files on exit (in java.io.DeleteOnExitHook), these files are locked and cannot be deleted (File#delete returns false).