jasperreports icon indicating copy to clipboard operation
jasperreports copied to clipboard

warning in 6.8.0 with java 11

Open gestshb opened this issue 6 years ago • 17 comments
trafficstars

I am using jasper report 6.8.0 in my project and i get this warning when i upgrade to java 11

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by net.sf.jasperreports.engine.util.ClassUtils (jar:file:/home/ahmed/Public/Projects/ERPSystem-Java11/oras/oras.jar!/BOOT-INF/lib/jasperreports-6.8.0.jar!/) to constructor com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl() WARNING: Please consider reporting this to the maintainers of net.sf.jasperreports.engine.util.ClassUtils WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

i get it when i invoke this line JasperCompileManager.compileReportToStream(getClass().getResourceAsStream(jasper), fileOutputStream);

gestshb avatar May 08 '19 16:05 gestshb

The warning comes from JasperReports XML parsing code which instantiates a grammar cache by reflection when it detects the Xerces parser included in Oracle JRE (under com.sun.org.apache.xerces) being used. Details about Xerces grammar caching can be found at http://xerces.apache.org/xerces2-j/faq-grammars.html

Grammar caching provides a performance improvement on JRXML parsing, which is usually performed during report compilation. It is currently implemented for Oracle JRE Xerces and for the original Apache Xerces.

There are several ways to get rid of the illegal reflective access warning:

  1. Grant reflective access to com.sun.org.apache.xerces.internal.util classes to the module which JasperReports is part of. That would involve passing --add-opens java.xml/com.sun.org.apache.xerces.internal.util=<module-name|ALL-UNNAMED> as option to the Java process.
  2. Add an Apache Xerces jar to the application classpath, so that it gets used as SAX implementation instead of the Oracle JRE Xerces.
  3. Set net.sf.jasperreports.compiler.xml.parser.cache.schemas=false in jasperreports.properties. This would disable grammar caching for both Apache Xerces and Oracle JRE Xerces.

We're of course considering what to do to avoid the warning in the future. Some options are:

  1. Remove the grammar caching optimization for Oracle JRE Xerces. The performance impact would probably not be noticeable in most use cases. (We could also keep the optimization for applications that still use Java 8, and remove it once we drop support for Java 8.)
  2. Change the net.sf.jasperreports.compiler.xml.parser.cache.schemas property to default to false. Grammar caching would only be enabled for people who explicitly set the property.
  3. Introduce finer grained configuration properties to enable/disable grammar caching individually for Apache Xerces and for Oracle JRE Xerces, and have the latter default to false.
  4. Try a different way of configuring grammar caching for Xerces, namely via XMLGrammarCachingConfiguration. Not sure though if it would work in the context of JasperReports XML parsing.

dadza avatar Jul 17 '19 14:07 dadza

Is the property "net.sf.jasperreports.compiler.xml.parser.cache.schemas" still valid? I am using jasperreport 6.12.1 jar with custom property <property name="net.sf.jasperreports.compiler.xml.parser.cache.schemas" value="false"/>

No change. I still get the error message:

WARNING: Illegal reflective access by net.sf.jasperreports.engine.util.ClassUtils (file:/C:/Users/user/.m2/repository/net/sf/jasperreports/jasperreports/6.12.1/jasperreports-6.12.1.jar) to constructor com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl()

Paul6552 avatar Mar 10 '20 14:03 Paul6552

Is the property "net.sf.jasperreports.compiler.xml.parser.cache.schemas" still valid? I am using jasperreport 6.12.1 jar with custom property <property name="net.sf.jasperreports.compiler.xml.parser.cache.schemas" value="false"/>

No change. I still get the error message:

WARNING: Illegal reflective access by net.sf.jasperreports.engine.util.ClassUtils (file:/C:/Users/user/.m2/repository/net/sf/jasperreports/jasperreports/6.12.1/jasperreports-6.12.1.jar) to constructor com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl()

You have to create the file jasperreports.properties, write this line on it: net.sf.jasperreports.compiler.xml.parser.cache.schemas=false and then put it under src/main/resources (at least this way it worked for me on a Spring Boot 2 application)

Hope it helps :)

durimkryeziu avatar Feb 15 '21 16:02 durimkryeziu

Is the property "net.sf.jasperreports.compiler.xml.parser.cache.schemas" still valid? I am using jasperreport 6.12.1 jar with custom property <property name="net.sf.jasperreports.compiler.xml.parser.cache.schemas" value="false"/> No change. I still get the error message: WARNING: Illegal reflective access by net.sf.jasperreports.engine.util.ClassUtils (file:/C:/Users/user/.m2/repository/net/sf/jasperreports/jasperreports/6.12.1/jasperreports-6.12.1.jar) to constructor com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl()

You have to create the file jasperreports.properties, write this line on it: net.sf.jasperreports.compiler.xml.parser.cache.schemas=false and then put it under src/main/resources (at least this way it worked for me on a Spring Boot 2 application)

Hope it helps :)

Thank @durimkryeziu in my case it worked

volverinejr avatar Mar 26 '21 21:03 volverinejr

@dadza Thanks :) Worked for me as well.

anishb266 avatar Apr 16 '21 16:04 anishb266

It is also working with Quarkus :-)

Side question: Why can't this be solved directly in the code of jasperreport?

Paul6552 avatar Apr 29 '21 06:04 Paul6552

Please be aware this will prevent JasperReports to work out of the box with JDK 17 LTS which will ship in September.

marschall avatar Jul 26 '21 16:07 marschall

@marschall From where did you get this information? And if this is correct do you have already the solution/fix for this?

Paul6552 avatar Jul 26 '21 16:07 Paul6552

@Paul6552 JEP 403: Strongly Encapsulate JDK Internals → all illegal access will throw an exception and you will have to add --add-opens command line arguments to prevent this

marschall avatar Jul 26 '21 17:07 marschall

Not completely sure if the owners of this library have to change some internal code or the programmers using this library. Anyway thanks for the information :)

Paul6552 avatar Jul 27 '21 05:07 Paul6552

work for me thanks @durimkryeziu

nilupulheshan1995 avatar Jul 27 '21 07:07 nilupulheshan1995

Is the property "net.sf.jasperreports.compiler.xml.parser.cache.schemas" still valid? I am using jasperreport 6.12.1 jar with custom property <property name="net.sf.jasperreports.compiler.xml.parser.cache.schemas" value="false"/> No change. I still get the error message: WARNING: Illegal reflective access by net.sf.jasperreports.engine.util.ClassUtils (file:/C:/Users/user/.m2/repository/net/sf/jasperreports/jasperreports/6.12.1/jasperreports-6.12.1.jar) to constructor com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl()

You have to create the file jasperreports.properties, write this line on it: net.sf.jasperreports.compiler.xml.parser.cache.schemas=false and then put it under src/main/resources (at least this way it worked for me on a Spring Boot 2 application)

Hope it helps :)

with Java v 11 and dependency jasperreports v 6.18.1 Me salvaste , saludos work for me thanks @durimkryeziu

adonayjp avatar Dec 24 '21 18:12 adonayjp

It is also working with Quarkus :-)

Side question: Why can't this be solved directly in the code of jasperreport?

please help sir, i use quarkus, and still have this issue

lokih avatar Dec 13 '22 12:12 lokih

On JDK 16+ this becomes an error

This helped:

Add an Apache Xerces jar to the application classpath, so that it gets used as SAX implementation instead of the Oracle JRE Xerces.

Up-to-date (21-01-2022) dependency so you don't have to search:

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.12.2</version>
</dependency>

s-volkov-1 avatar May 18 '23 19:05 s-volkov-1

We're of course considering what to do to avoid the warning in the future

@dadza Has any progress been made on this issue? With JDK 17 LTS being out for some time now and JDK 21 LTS being around the corner, JasperReports should have a better out of the box experience.

Can't jasperreports add a dependency on Apache Xerces and simply remove the code supporting Oracle JRE Xerces?

jnehlmeier avatar Jul 12 '23 14:07 jnehlmeier

I am not a SpringBoot project, what should I do?

Marblog avatar Aug 04 '23 03:08 Marblog