TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.03k stars 397 forks source link

Value (variable) displayed in GroupFooter after upgrading from JasperReports API 6.3.1 to 6.7.0 is null. This happens on page 11/14 on the report. #51

Open ghost opened 5 years ago

ghost commented 5 years ago

Details:

Variable has the following properties:

Issue occurs when after printing the GroupHeader on the 10th page there is not enough space to print the Detail band so the variables are recalculated.

The flow is something like: In the JRVerticalFiller.fillDetail() the condition detailBand.getBreakHeight() > columnFooterOffsetY - offsetY in the while loop is false leading to JRVerticalFiller.fillColumnBand() being invoked. When the detail is being is filled the JRPrintBand would overflow because one of the fields stretches. As the JRPrintBand will overflow it causes JRVerticalFiller.fillColumnBreak() to be invoked and the JRPrintBand to be refilled. After JRVerticalFiller.fillColumnBreak() JRCalculator.recalculateVariables() is called. This method sets the variables incremented value to the previous incremented value but as the variable was reset when the group changed the previous incremented value is null.

ghost commented 5 years ago

Below is a better description of the flow

JRVerticalFiller.fillReportContent()
    JRCalculator.estimateGroupRuptures() //This sets group as changed.
    JRCalculator.initializeVariables(ResetTypeEnum.GROUP, IncrementTypeEnum.GROUP); //sets variables previousIncrementedValue to NULL
    fillGroupHeaders(false); //no issues here
    fillDetail();
        calculator.calculateVariables(true); // sets variable value as expected. Variable isInitialized set to false.
        fillColumnBand(detailBand, JRExpression.EVALUATION_DEFAULT, !atLeastOneDetailBandPrinted); //band overflows
            JRCalculator.recalculateVariables(); //sets variable incremented value back to previous which is NULL. As variable is initialized the value is never incremented properly again.
ghost commented 5 years ago

Fixed the issue by updating the JRCalculator.recalculateVariables() method to be:

protected void recalculateVariables() throws JRException {
        if (variables != null) {
            for (JRFillVariable variable : variables) {
                variable.setIncrementedValue(variable.getPreviousIncrementedValue());

                if (variable.getResetTypeValue() == ResetTypeEnum.GROUP) {
                    JRFillGroup group = (JRFillGroup) variable.getResetGroup();
                    variable.setInitialized(group.hasChanged());
                }
            }
        }

        calculateVariables(false);
    }
teodord commented 5 years ago

Hi, Do you have a simple JRXML demonstrating this problem? Thank you, Teodor

ghost commented 5 years ago

@teodord ... I don't have any sample JRXML. We have a suite of integration tests we run after deploying any code and this is where the failure occurred. In terms of report layout we are just using the Column Header, Detail, Group Header and Group Footer bands.

Just to note our application builds a JasperDesign on the fly when we are executing a report. We don't save static JRXMLs