views:

95

answers:

1

I'm working on a system that uses Jasper reports. Recently it started throwing this error:

org.apache.commons.beanutils.ConversionException: Unparseable date: "03/03/1981"
        at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:241)
        at org.apache.commons.beanutils.locale.LocaleConvertUtilsBean.convert(LocaleConvertUtilsBean.java:285)
        at net.sf.jasperreports.engine.data.JRAbstractTextDataSource.convertStringValue(JRAbstractTextDataSource.java:69)
        at net.sf.jasperreports.engine.data.JRXmlDataSource.getFieldValue(JRXmlDataSource.java:313)
        at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:823)
        at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:787)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1478)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:125)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:942)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:860)
        at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:84)
        at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
        at XmlJasperInterface.report(XmlJasperInterface.java:89)
        at XmlJasperInterface.main(XmlJasperInterface.java:63)
Caused by: java.text.ParseException: Unparseable date: "03/03/1981"
        at java.text.DateFormat.parse(DateFormat.java:337)
        at net.sf.jasperreports.engine.util.JRDateLocaleConverter.parse(JRDateLocaleConverter.java:84)
        at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:232)
        ... 13 more

I'm not sure what caused it. We've also recently upgraded Jasper reports but I remember it was working after the upgrade.

I've found a blog post titled BeanUtils, Digester, and Type Conversion which points to add these lines:

String pattern = "MM/dd/yyyy";
Locale locale = Locale.getDefault();
DateLocaleConverter converter = new DateLocaleConverter(locale, pattern);
converter.setLenient(true);
ConvertUtils.register(converter, java.util.Date.class);

but they've changed nothing. I still get the same error.

The line that triggers the error is this one:

jasperPrint = JasperFillManager.fillReport(jasperReport, null, new JRXmlDataSource(System.in, selectCriteria));

Thanks.

Update: Downgrading Jasper Reports to 1.1.0 made it work again, so it was most likely the upgrade that broke it.

+1  A: 

You will need to set a date pattern in your datasource, like this:

JRXmlDataSource datasource = new JRXmlDataSource(....);
datasource.setDatePattern("MM/dd/yyyy");
pascal betz