ClassCast exception: Jasper is no thrill

0
It's hard to be optimistic after 3 days of fiddling with Jasper and IReport. Nonetheless I will describe my latest issue:


I get a Class Cast exception when retrieving a custom data source at the subreport level. And knowing there is no effective means to understand what's going on under the covers (since this tool is very deficient in providing such means to developers) I decided to do an experiment.


I wanted to determine what was in the REPORT_DATA_SOURCE parameter at the top of the master report.


So I setup a parameter to retrieve a value that I assumed to be my custom data source. (For my connection setup had already tested OK with my custom datasource "com.catalystwms.cct.web.beans.reports.TestDataSource" within IReport)


But when I run this snippet of code in my report, out pops the Class cast exception. Why? Why doesn't this work? (All files are attached.)


Code:
<parameter name="JR_REPORT_DATA_SOURCE" isForPrompting="false" class="com.catalystwms.cct.web.beans.reports.TestDataSource"><br />
<defaultValueExpression ><![CDATA[((com.catalystwms.cct.web.beans.reports.TestDataSource)$P{REPORT_DATA_SOURCE})]]></ defaultValueExpression><br />
</parameter></td></tr></tbody></table><br />
<br />
<br />
IReport TRACE<br />
==============<br />
 Time zone: default<br />
Error filling print... <br />
ENTERED TestDataSourceFactory.getTheDatasource() ENTERED TestDataSource() CONSTRUCTOR ENTERED addRow index=0 ENTERED TestDataSource(List) CONSTRUCTOR ENTERED TestDataSource.putSubDataSourceFromRow() key=Tasks ENTERED addRow index=1 ENTERED TestDataSource(List) CONSTRUCTOR ENTERED TestDataSource.putSubDataSourceFromRow() key=Tasks java.lang.ClassCastException: com.catalystwms.cct.web.beans.reports.TestDataSource     at TestDataSource_1154553627259_783159.evaluate(TestDataSource_1154553627259_783159:126)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:172)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:539)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:507)     at net.sf.jasperreports.engine.fill.JRFillDataset.setFillParameterValues(JRFillDataset.java :631)     at net.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java: 593)     at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:879)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:708)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685)     at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)     at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:728)     at java.lang.Thread.run(Unknown Source) NESTED BY : java.lang.ClassCastException: com.catalystwms.cct.web.beans.reports.TestDataSource     at TestDataSource_1154553627259_783159.evaluate(TestDataSource_1154553627259_783159:126)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:172)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:539)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:507)     at net.sf.jasperreports.engine.fill.JRFillDataset.setFillParameterValues(JRFillDataset.java :631)     at net.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java: 593)     at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:879)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:708)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685)     at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)     at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:728)     at java.lang.Thread.run(Unknown Source) NESTED BY : net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :      Source text : ((com.catalystwms.cct.web.beans.reports.TestDataSource) $P{REPORT_DATA_SOURCE})     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:183)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:539)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:507)     at net.sf.jasperreports.engine.fill.JRFillDataset.setFillParameterValues(JRFillDataset.java :631)     at net.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java: 593)     at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:879)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:708)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685)     at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)     at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:728)     at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassCastException: com.catalystwms.cct.web.beans.reports.TestDataSource     at TestDataSource_1154553627259_783159.evaluate(TestDataSource_1154553627259_783159:126)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:172)     ... 11 more <br />
Print not filled. Try to use an EmptyDataSource...!<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre> [file name=TestDataSource-ee74ec388dcb63ad3fc8aec51997a982.zip size=23342]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/TestDataSource-ee74ec388dcb63ad3fc8aec51997a982.zip[/file] :«»sick: </td></tr></tbody></table>
kjhuebner's picture
Joined: Jul 31 2006 - 3:01am
Last seen: 15 years 5 months ago

5 Answers:

0
[file name=TestDataSource-3454e0948eb140276eb408b731c67e93.zip size=23342]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Tes...
kjhuebner's picture
Joined: Jul 31 2006 - 3:01am
Last seen: 15 years 5 months ago
0
This is a class loading problem in iReport. What happens is that iReport uses one class loader to load the data source provider class and obtain the data source instance and another class loader to fill the report. Because of this, the value of the $P{REPORT_DATA_SOURCE} parameter is an instance of the TestDataSource loaded by the first class loader, and the expression tries to convert it to the TestDataSource class loaded by the second class loader. Hence the ClassCastException.

You should follow this up on the iReport forum. I'll also let Giulio know about this.

On an unrelated matter, I've noticed this in your report:
Code:
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression></td></tr></tbody></table><br />
<br />
This is something that should not be done (unless maybe in really exotic cases).  A data source cannot be reused by multiple report execution (and a subreport instantiation is equivalent to a report execution), because the data source is iterated on and the rows it produces get exhausted while the report is executed (you can compare with a java.util.Iterator).  You need to create a fresh data source for every subreport instantiation.<br />
<br />
Regards,<br />
Lucian
lucianc's picture
7439
Joined: Jul 17 2006 - 1:10am
Last seen: 3 days 14 hours ago
0
Thanks Lucian for your reply.

If I'm hearing you right, IReport forbids me from using a custom datasource during the fill operation. Sounds like a major bug.

Also, please ignore the subreport's datasource entry you noticed (you're very observant :woohoo: ). My intention was to retrieve the subreport datasource by:

<dataSourceExpression><![CDATA[((com.catalystwms.report.TestDataSource)$P{REPORT_DATA_SOURCE}).getSubDataSource("Tasks")]]></dataSourceExpression>

The above code started this whole exploration. This failed due to the Class Cast exception problem. We now know this a class loader bug in IReport.

I hope you guys fix this soon. Without this bug fix in IReport, its going to be difficult or impossible to incorporate Jasper into our company product.

Ken
kjhuebner's picture
Joined: Jul 31 2006 - 3:01am
Last seen: 15 years 5 months ago
0
GREAT GREAT GREAT Lucian!

You have found the bug I was looking for months :laugh:

Now the big problem is how to fix it...it's not a simple problem, I mean it should use always the same classloader, I have to figure out why the JVM want use a different classloader if the thread is always the same... it is right Lucian?

Giulio
giulio's picture
46892
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 year 10 months ago
0
Hey, I have confidence in all of you -- Giulio, Lucian, and the JasperTeam! If I wasn't so busy with my own technical work, I'd be happy to lend a hand.

Ken

:cheer:
kjhuebner's picture
Joined: Jul 31 2006 - 3:01am
Last seen: 15 years 5 months ago
Feedback