Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Image fails with Exception java.lang.ExceptionInInitializerError while using Jasper Report #2696

Closed
Mahaswami opened this issue Jul 21, 2020 · 9 comments
Assignees

Comments

@Mahaswami
Copy link

Describe the issue
Native build fails with error while generating report using Jasper reports library. Works fine in JVM mode and report gets generated.

Error: Classes that should be initialized at run time got initialized during image building:
 org.eclipse.jdt.internal.compiler.parser.Parser was unintentionally initialized at build time. org.eclipse.jdt.internal.compiler.parser.Parser has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=org.eclipse.jdt.internal.compiler.parser.Parser
org.eclipse.jdt.internal.compiler.util.Util was unintentionally initialized at build time. org.eclipse.jdt.internal.compiler.util.Util has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=org.eclipse.jdt.internal.compiler.util.Util

com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 org.eclipse.jdt.internal.compiler.parser.Parser was unintentionally initialized at build time. org.eclipse.jdt.internal.compiler.parser.Parser has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=org.eclipse.jdt.internal.compiler.parser.Parser
org.eclipse.jdt.internal.compiler.util.Util was unintentionally initialized at build time. org.eclipse.jdt.internal.compiler.util.Util has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=org.eclipse.jdt.internal.compiler.util.Util

	at com.oracle.svm.core.util.UserError.abort(UserError.java:68)

Note: Added --initialize-at-build-time=org.eclipse.jdt.internal.compiler.parser.Parser,org.eclipse.jdt.internal.compiler.util.Util and able to generate the native image.

But running the native image fails with the below exception

Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:290)
	at java.lang.Class.ensureInitialized(DynamicHub.java:499)
	at net.sf.jasperreports.engine.JasperCompileManager.getDefaultInstance(JasperCompileManager.java:201)
	at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:576)
	at com.mahaswami.nativejasper.ReportGenerator.generatePdfReport(ReportGenerator.java:14)
	at com.mahaswami.nativejasper.MainClass.main(MainClass.java:11)

Steps to reproduce the issue

Reproducer project available at https://github.com/MahaswamiSoftware/native-jasper-report

Describe GraalVM and your environment:

  • GraalVM version - 20.1.0
  • JDK major version: 11
  • OS: linux mint
  • Architecture: AMD64
@Mahaswami
Copy link
Author

Update:

Able to proceed further by using the tracing agent to generate the configuration files and specifying these configuration files during native image build.

However now stuck with the below error while running the native executable.

Exception in thread "main" java.lang.InternalError: java.lang.reflect.InvocationTargetException
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
	at java.security.AccessController.doPrivileged(AccessController.java:83)
	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
	at sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:189)
	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:223)
	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:251)
	at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:75)
	at net.sf.jasperreports.engine.util.JRGraphEnvInitializer.initializeGraphEnv(JRGraphEnvInitializer.java:58)
	at net.sf.jasperreports.engine.fill.BaseReportFiller.<init>(BaseReportFiller.java:136)
	at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:273)
	at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:79)
	at net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:251)
	at net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:272)
	at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:156)
	at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:145)
	at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:758)
	at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1074)
	at com.mahaswami.nativejasper.ReportGenerator.generatePdfReport(ReportGenerator.java:24)
	at com.mahaswami.nativejasper.MainClass.main(MainClass.java:35)
Caused by: java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)
	... 18 more
Caused by: java.lang.UnsatisfiedLinkError: sun.font.FontConfigManager.getFontConfigVersion()I [symbol: Java_sun_font_FontConfigManager_getFontConfigVersion or Java_sun_font_FontConfigManager_getFontConfigVersion__]
	at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:145)
	at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:57)
	at sun.font.FontConfigManager.getFontConfigVersion(FontConfigManager.java)
	at sun.font.FcFontConfiguration.readFcInfo(FcFontConfiguration.java:455)
	at sun.font.FcFontConfiguration.init(FcFontConfiguration.java:94)
	at sun.font.FcFontConfiguration.<init>(FcFontConfiguration.java:76)
	at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:713)
	at sun.font.SunFontManager$2.run(SunFontManager.java:367)
	at java.security.AccessController.doPrivileged(AccessController.java:83)
	at sun.font.SunFontManager.<init>(SunFontManager.java:312)
	at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
	at sun.awt.X11FontManager.<init>(X11FontManager.java:56)
	... 20 more

Tried to load the library libfontmanager.so using NativeLibrarySupport.singleton().loadLibrary() but to no avail.

Updated the reproducer project below with the JNI and reflection configuration files.
https://github.com/MahaswamiSoftware/native-jasper-report

@LightCampy
Copy link

I found that similar problems happens in Micronaut Redis and spring-graalvm-native. Perhaps we can refer to these issues and their fix micronaut-core#3713, micronaut-core#48, spring-graalvm-native#163,spring-graalvm-native#185 to find more context about the bug (e.g. the version Information and the commnad). Also the similar problem is mentioned in helidon#1941

@dhombios
Copy link

dhombios commented Apr 13, 2021

I'm having a similar issue while compiling a Jasper Reports based application in windows:

Native-tools options: native-image -H:+ReportExceptionStackTraces -H:-CheckToolchain --no-fallback

To see how the classes got initialized, use --trace-class-initialization=org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching,org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching$CheckMode,org.eclipse.jdt.internal.compiler.parser.Parser,org.eclipse.jdt.internal.compiler.util.Util
[Program.exe:15260]     analysis:  21,437.43 ms,  2.75 GB
Error: Classes that should be initialized at run time got initialized during image building:
 org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching
org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching$CheckMode was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching$CheckMode got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching$CheckMode
org.eclipse.jdt.internal.compiler.parser.Parser was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.parser.Parser got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.parser.Parser
org.eclipse.jdt.internal.compiler.util.Util was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.util.Util got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.util.Util

com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching
org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching$CheckMode was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching$CheckMode got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching$CheckMode
org.eclipse.jdt.internal.compiler.parser.Parser was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.parser.Parser got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.parser.Parser
org.eclipse.jdt.internal.compiler.util.Util was unintentionally initialized at build time. To see why org.eclipse.jdt.internal.compiler.util.Util got initialized use --trace-class-initialization=org.eclipse.jdt.internal.compiler.util.Util

        at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
        at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:539)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:226)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$8(NativeImageGenerator.java:740)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:70)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:740)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:563)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:476)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Error: Image build request failed with exit status 1

Describe GraalVM and your environment:

  • GraalVM version - GraalVM Community Edition 21.0.0.2
  • JDK major version: 11
  • OS: Windows
  • Architecture: AMD64
  • Visual Studio version: Visual Studio 2019 (MSVC 14.28.29910; x64 Native Tools Command Prompt)

@pquiring
Copy link

You need to copy ${java.home}\lib\*font* to .\lib in app folder which is where Java looks for font config files.

@dhombios
Copy link

Thanks for your answer, pquiring. I'm currently fixing another problem I'm having with jasper and as soon as I can I'll try copying them.
If I wanted to use custom truetype fonts that may not be installed in the computer, would copying also them to that folder make them available to the final executable?

@pquiring
Copy link

It might be ./lib/fonts but I haven't tested that.

@abdoulrahim
Copy link

I looking to use Jasper Report in Quarkus native, but I can't found the solution. Is there any update about this bug?

@chirontt
Copy link

chirontt commented Apr 14, 2022

Seems significant improvements in AWT/Swing support have occurred since the OP reported this issue in the 20.1 version. In GraalVM 22.0.0.2 version, the reproducer project above works fine for me.

To test it, I've forked the OP's reproducer project, and updated extensively its pom.xml so that Maven alone can be used to build the native image. The fork is here.

To produce the native image:

mvn compile exec:exec package

(the exec:exec goal is important, as it generates the native image config files using the agent)

Then to run the generated native image, e.g. in Linux:

./target/native-image/native-jasper-report

or in Windows:

target\native-image\native-jasper-report.exe -Djava.home="%JAVA_HOME%"

and the report file CarReport.pdf is properly created in the current directory by the native image's execution.

@vjovanov
Copy link
Member

@chirontt thanks for verifying that it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants