Precondition:
JasperReports 4.1.2
The same issue seemed to be produced on each public version from 4.0.1 to 4.1.2
Trigger:
Create a report that uses $X{IN, col, param} and make sure the parameter being used is an array with more than one element.
Symptom:
Only one ? will be added to the SQL for this clause. It will then attempt to set values on the PreparedStatement for each element in the array. This will fail as there are more values than parameter placeholders.
Root Cause:
In net.sf.jasperreports.engine.query.JRSqlAbstractInClause, the convert method is using Arrays.asList to take the array and produce a Collection. The resulting Collection only has one element, the source array.
Solution:
Cast the Object parameter to an Object[]
from...
if( paramValue.getClass().isArray() ) {
paramCollection = Arrays.asList( paramValue );
}
to...
if( paramValue.getClass().isArray() ) {
paramCollection = Arrays.asList( (Object[])paramValue );
}
In version 4.1.2, the significant line number is 234.
Recommended Comments