MalformedByteSequenceException with Grails jasper plugin 1.1.6

03 / Dec / 2010 by Sachin 4 comments

Hi All,

I was facing a lot of problems with creating pdf reports using jasper plugin 1.1.6 in grails, Though I had earlier worked with 0.9.5 and 0.9.7 versions of the plugin with a lot of ease but some how 1.1.6 version of plugin was not generating reports  it always ended up throwing MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

[java]com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java:1619)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java:1657)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:193)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.commons.digester.Digester.parse(Digester.java:1647)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:241)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:228)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:216)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:199)
at net.sf.jasperreports.engine.JasperCompileManager$compileReport.call(Unknown Source)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at java.lang.Thread.run(Thread.java:662)[/java]

I tried various things like changing the header of the jrxml file, adding new attributes in jasperReport tag and changing encoding type but to no Avail. Then I tried generating report without the .jasper files and deleted all jasper files except for sub-reports (sub-reports need to be in a pre-compiled state for the plugin to work)  and thing started working. For some strange reason the plugin was throwing exception when jasper report was available but if the report was compiled on the fly the plugin had no trouble with it. I am not sure what may be the reason may be I-report or something, but I got a move on. Hope You will too.

With Regards

Sachin Anand

sachin[at]intelligrape[dot].com

FOUND THIS USEFUL? SHARE IT

comments (4)

  1. J. M. Rajala

    Hi,

    I stumbled upon this same problem while trying to make the Grails Jasper plugin work with reports containing subreports, which needed to be pre-compiled to .jasper. Like Sachin I found out that if the main report is not pre-compiled with them but on the fly, then the plugin works. The reason for the “MalformedByteSequenceException” seems to be a bug in JasperService.groovy (in generatePrinter() method): it decides on whether compilation is needed by looking at the report file name extension. If no extension has been defined in the name parameter you have supplied, it is resolved in JasperReportDef. As long as you have a jrxml version only, the if/else condition in the Service class works since it default to a jrxml having been loaded and needing compilation, but in case of implicit .jasper extension the name is not appended with that (in the logic inside JasperReportDef) and JasperService tries to compile the .jasper file again, which throws the exception.
    So until this is fixed in the plugin, you should be able to get this working by explicitly defining the main report name parameter with .jasper extension, if that reports has been pre-compiled.

    Regards,
    JM

    Reply
  2. Nitin

    I want view jasper report by using below code but it giving me Exceptions.
    Please help me

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    try {
    String reportName = “C:\\New Folder\\report4.jasper”;
    java.io.InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);
    Class.forName(“com.mysql.jdbc.Driver”);
    Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/college”, “root”, “”);
    JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), conn);
    JasperViewer jv = new JasperViewer(jasperPrint);
    jv.setVisible(true);
    } catch (ClassNotFoundException ex) {
    System.out.println(ex);

    } catch (JRException ex) {
    System.out.println(“1..”+ex);

    } catch (SQLException ex) {
    System.out.println(“2…”+ex);

    }
    }

    Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2264)
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2277)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2748)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
    at java.io.ObjectInputStream.(ObjectInputStream.java:280)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:191)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:361)
    at javaapplication15.NewJFrame.jButton1ActionPerformed(NewJFrame.java:80)
    at javaapplication15.NewJFrame.access$000(NewJFrame.java:27)
    at javaapplication15.NewJFrame$1.actionPerformed(NewJFrame.java:50)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

    Reply
  3. Sebastian Hohns

    Hi Sachin

    just found your message here (a few days late, please use the grails mailing list if you require a faster response ;)). As the author of the grails jasper plugin i can tell you that you are not the only one with this problem. This is a common problem with iReport (you will find various reports all over the net) and has nothing to do with the grails plugin.
    In most cases it helps if you install a iReport plugin “XML and Schema” see:

    this should give you a stacktrace you can work with.
    This is a odd bug, i even know cases where it’s enough to simply compile the report on another system (for example i was able to reproduce this bug on a XP install, but exactly the same report worked fine if i compiled it on Linux).

    Greetings

    Reply

Leave a Reply to Sebastian Hohns Cancel reply

Your email address will not be published. Required fields are marked *