TIBCOSoftware / jasperreports

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

Report parameter map must be mutable #492

Closed bjorndarri closed 3 weeks ago

bjorndarri commented 3 weeks ago

I'd love to be able to use Map.of() (or other immutable map constructs) when specifying report parameters, but BaseReportFiller adds items to the map, which causes an UnsupportedOperationException to be thrown in case of an immutable map.

The solution.

Make a copy of the parameterValues map, received via ReportFiller.fill()

For example:

@Override
@continuable
public JasperPrint fill(Map<String,Object> parameterValues, Connection conn) throws JRException
{
    if (parameterValues == null)
    {
        parameterValues = new HashMap<>();
    }
    else 
    {
        parameterValues = new HashMap<>(parameterValues);
    }

    setConnectionParameterValue(parameterValues, conn);

    return fill(parameterValues);
}
teodord commented 3 weeks ago

Hi,

I'm afraid that after so many years, it is a bit late to make such change. The map with the parameters values is available in report expressions and in scriptlets through the built-in variable called REPORT_PARAMETERS_MAP. Chances are some people might use this to return values calculated during report execution.

The possible damage outweighs the benefit.

Thank you, Teodor

bjorndarri commented 3 weeks ago

I agree, the benefits are quite small, thanks anyway.