Skip to content

JacksonReportLoader incorrectly wants XML to contain no metadata/namespace information #521

@lanseg

Description

@lanseg

"JRException: Unable to load report" when trying to use JasperCompileManager or any other class that relies on the underlying JacksonReportLoader.java. That happens because of the following line:

case XMLEvent.START_ELEMENT:
if (elementName.equals(reader.getLocalName())
&& (reader.getNamespaceURI() == null || reader.getNamespaceURI().isEmpty()))
{
foundRoot = true;
}

Line misses and exclamation mark and looks like a typo.

Detailed steps to reproduce:

  1. Run this java code
package org.lanseg.demo;

import net.sf.jasperreports.engine.JasperCompileManager;

public class Main {
  public static void main(String[] args) throws Exception {
      JasperCompileManager.compileReportToFile("sample.xml", "sample-report");
  }
}

for the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<jasperReport xmlns="https://jasperreports.sourceforge.net/jasperreports" 
              xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
              xsi:schemaLocation="https://jasperreports.sourceforge.net/jasperreports https://jasperreports.sourceforge.net/xsd/jasperreport.xsd" 
              name="report" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9a3e59f5-6675-48cf-ad74-9c42b5a5b290">
	<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
	<property name="com.jaspersoft.studio.unit." value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
	<parameter name="mapSubReport" class="java.lang.String"/>
	<title>
		<band height="390" splitType="Stretch">
			<staticText>
				<reportElement x="0" y="1" width="800" height="50" uuid="3988392b-f1e2-4eda-9cb4-7caa2b3eb0cc"/>
				<textElement textAlignment="Center">
					<font size="36"/>
				</textElement>
				<text><![CDATA[Map]]></text>
			</staticText>
			<subreport>
				<reportElement x="0" y="51" width="780" height="330" uuid="fa145068-76a5-4834-98ed-ce65b1976b3d">
					<property name="local_mesure_unitwidth" value="pixel"/>
					<property name="com.jaspersoft.studio.unit.width" value="px"/>
					<property name="local_mesure_unitheight" value="pixel"/>
					<property name="com.jaspersoft.studio.unit.height" value="px"/>
				</reportElement>
				<subreportExpression><![CDATA[$P{mapSubReport}]]></subreportExpression>
			</subreport>
		</band>
	</title>
</jasperReport>

And get the result:

Exception in thread "main" net.sf.jasperreports.engine.JRException: Unable to load report
        at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:173)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:150)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:121)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:99)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:90)
        at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:246)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:547)
        at org.lanseg.demo.Main.main(Main.java:7)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions