java.lang.ClassCastException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Jasper report generated classes, are not loaded correct by this Class loader. Create a bean which compiles a jasper report, and fills a jasper report. The fill step from the Jasper report will work with the normal class loader. If called from a main() / web container, this report works normally. If called from a JUnit tests that extends from AbstractJpaTests, it will not work. The following error will occur: java.lang.ClassCastException: YOUR_REPORT_NAME_1180710532958_496838 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:83) I have seen the generated class, and it does extend net.sf.jasperreports.engine.fill.JREvaluator so it should bew possible to cast it to this type. the JrClassLoader from Jasper reports, has the OrmXmlOverridingShadowingClassLoader as parent class loader. The class Classloader, method protected final Class<?> defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain) is called, and gives a wrong class as result Jasper reports code: // compile report String myReportXml = "<?xml version=\"1.0\"?> " + "<!DOCTYPE jasperReport " + "PUBLIC \"-//JasperReports//DTD Report Design//EN\" "+ "\"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd\"> " + "<jasperReport name=\"Simple_Report\"> " + "<detail>" + "<band height=\"20\">" + "<staticText>" + "<reportElement x=\"180\" y=\"0\" width=\"200\" height=\"20\"/>" + "<text><![CDATA[Hello World!]]></text>" + "</staticText>" + "</band>" + "</detail>" + "</jasperReport>"; // Using depricated StringBufferInputStream // No method accepting a StringReader is available JasperReport myJasperReport = JasperCompileManager.compileReport( new StringBufferInputStream(myReportXml ); // fill report, this steps failed if OrmXmlOverridingShadowingClassLoader is used! JasperPrint myJasperPrint = JasperFillManager.fillReport( myJasperReport, new HashMap(), new JREmptyDataSource()); Workaround: do not test Jasper reports in AbstractJpaTests, but use other JUnit superclasses instead.
    via by Kees van Dieren,
  • Jasper report generated classes, are not loaded correct by this Class loader. Create a bean which compiles a jasper report, and fills a jasper report. The fill step from the Jasper report will work with the normal class loader. If called from a main() / web container, this report works normally. If called from a JUnit tests that extends from AbstractJpaTests, it will not work. The following error will occur: java.lang.ClassCastException: YOUR_REPORT_NAME_1180710532958_496838 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:83) I have seen the generated class, and it does extend net.sf.jasperreports.engine.fill.JREvaluator so it should bew possible to cast it to this type. the JrClassLoader from Jasper reports, has the OrmXmlOverridingShadowingClassLoader as parent class loader. The class Classloader, method protected final Class<?> defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain) is called, and gives a wrong class as result Jasper reports code: // compile report String myReportXml = "<?xml version=\"1.0\"?> " + "<!DOCTYPE jasperReport " + "PUBLIC \"-//JasperReports//DTD Report Design//EN\" "+ "\"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd\"> " + "<jasperReport name=\"Simple_Report\"> " + "<detail>" + "<band height=\"20\">" + "<staticText>" + "<reportElement x=\"180\" y=\"0\" width=\"200\" height=\"20\"/>" + "<text><![CDATA[Hello World!]]></text>" + "</staticText>" + "</band>" + "</detail>" + "</jasperReport>"; // Using depricated StringBufferInputStream // No method accepting a StringReader is available JasperReport myJasperReport = JasperCompileManager.compileReport( new StringBufferInputStream(myReportXml ); // fill report, this steps failed if OrmXmlOverridingShadowingClassLoader is used! JasperPrint myJasperPrint = JasperFillManager.fillReport( myJasperReport, new HashMap(), new JREmptyDataSource()); Workaround: do not test Jasper reports in AbstractJpaTests, but use other JUnit superclasses instead.
    via by Kees van Dieren,
  • Jasperreports VS Weblogic
    via by 865328,
    • java.lang.ClassCastException: YOUR_REPORT_NAME_1180710532958_496838 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:83)
    No Bugmate found.