java.lang.ClassCastException: YOUR_REPORT_NAME_1180710532958_496838 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator

Spring JIRA | Kees van Dieren | 10 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    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.

    Spring JIRA | 10 years ago | Kees van Dieren
    java.lang.ClassCastException: YOUR_REPORT_NAME_1180710532958_496838 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator
  2. 0

    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.

    Spring JIRA | 10 years ago | Kees van Dieren
    java.lang.ClassCastException: YOUR_REPORT_NAME_1180710532958_496838 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator

    Root Cause Analysis

    1. 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()
    2. JasperReports
      JRAbstractJavaCompiler.loadEvaluator
      1. net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:83)
      1 frame