Jump to content
Changes to the Jaspersoft community edition download ×

ClassCast exception: Jasper is no thrill


kjhuebner

Recommended Posts

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">
<defaultValueExpression ><![CDATA[((com.catalystwms.cct.web.beans.reports.TestDataSource)$P{REPORT_DATA_SOURCE})]]></ defaultValueExpression>
</parameter>

 

 

IReport TRACE

==============

Time zone: default

Error filling print...

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

Print not filled. Try to use an EmptyDataSource...!

Code:
[code] [file name=TestDataSource-ee74ec388dcb63ad3fc8aec51997a982.zip size=23342]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/TestDataSource-ee74ec388dcb63ad3fc8aec51997a982.zip[/file] :«»sick:
Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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>

 

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.

 

Regards,

Lucian

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...