Jaspersoft reports, "Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "BAM subreports #1""

Viewed 301

I have a simple Jasper report, that I simplified it at maximum and now it should give me a blank page but instead it gives me a "Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "BAM subreports #1"".

Jasper takes a long time to think and in the end displays the memory error.

The blockage that causes the supposed memory leak appears in the JasperFillManager.fillReport.

This is no a problem related to the allocated memory, I tried to increase the memory with the options "-Xms1140m -Xmx1140m" and it seems to think forever for a very simple report.

The report contains:

  • a main report that contains a single element: a subreport. The main report has a single record of type BAMHeader in the JRBeanCollectionDataSource, but no element from this record is displayed on the PDF because I deleted everything hoping I will detect the cause of the problem and in the end I remained with nothing but the problem.
  • a subreport that also displays nothing and accesses his data source with the expression "new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{BAMResults})". The BAMResults has a single row.

So the structure of the datasource is

BAMHeader= [ <-- main report is here and contains a single record
   BAMResults= [ 
       item1, <-- for this test a single record is in BAMResults
   ]
]

The xml for the main report is:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="BAM" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="13acf49e-4913-4d1b-bccc-113817ad15d1">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="BAMResults" class="java.util.List"/>
    <detail>
        <band height="192">
            <subreport overflowType="NoStretch">
                <reportElement x="2" y="150" width="530" height="30" uuid="e7898571-e6f1-4348-a3f8-2871775dd207"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{BAMResults})]]></dataSourceExpression>
                <subreportExpression><![CDATA["results.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>

The xml for the subreport is:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="results" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="34cb40f6-7f10-4c98-81fe-75101acc9691">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <detail>
        <band height="72" splitType="Stretch"/>
    </detail>
</jasperReport>

The java source code of the main class is:

public class JasperBAM {
    public static void main(String[] args) { 
        try {
            List<BAMHeader> bhs = BAMHeader.getBAMHeader();
            Map<String, Object> parameters = new HashMap<>();
            System.err.println("Start fill");
            JasperPrint jasperPrint = JasperFillManager.fillReport("JasperReports/BAM.jasper", parameters, new JRBeanCollectionDataSource(bhs));
            System.err.println("Stop fill");
            OutputStream outputStream = new FileOutputStream(new File("BAM.pdf"));
            JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
        } catch (Exception ex) {
            Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

The class that will populate the main report is:

public class BAMHeader {
    private List<BAMResult> BAMResults = new ArrayList<>();
    public static List<BAMHeader> getBAMHeader() {
        try {
            List<BAMHeader> bhs = new ArrayList<>();
            BAMHeader bh = new BAMHeader();
            bh.setBAMResults();
            bhs.add(bh);
            return bhs;
        } catch (Exception ex) {
            Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex);
            return  null;
        }
    }

    public void setBAMResults() {
        System.err.println("Start setBAMResults");
        this.BAMResults = BAMResult.getBAMResults();
        System.err.println("Stop setBAMResults");
    }
    public List<BAMResult> getBAMResults() {
        System.err.println("Start getBAMResults");
        return this.BAMResults;
    }

}

The class that will populate the subreport is:

public class BAMResult {
    public static List<BAMResult> getBAMResults() {
        try {
            List<BAMResult> brs = new ArrayList<>();
            BAMResult nt = new BAMResult();
            brs.add(nt);
            return brs;
        } catch (Exception ex) {
            Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex);
            return  null;
        }
    }
}

As a final observation, if I delete the single record from BAMResults the memmory problem dissapears.

UPDATE: I use jasperreports-6.17.0.jar

UPDATE: Apache netbeans profiler iamges

Profiling threads Profiling telemetry

1 Answers

If I replace in the main report XML the line

    <subreport overflowType="NoStretch">

with the line

    <subreport>

than the problem dissapeares.

But this looks like a Jasper BUG.

Related