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 Build fail with Quarkus-awt and pdfbox #26682

Closed
dilipdhankecha2530 opened this issue Jul 12, 2022 · 11 comments
Closed

Native Build fail with Quarkus-awt and pdfbox #26682

dilipdhankecha2530 opened this issue Jul 12, 2022 · 11 comments
Labels
area/native-image kind/bug Something isn't working triage/wontfix This will not be worked on

Comments

@dilipdhankecha2530
Copy link

dilipdhankecha2530 commented Jul 12, 2022

Describe the bug

We want to create image from pdf file and for that we are planning to use Quarkus and want to deploy as AWS lambda.

All things are working as expected if I build application as non native with below command.

./gradlew clean build

Now to improve performance, I want to build native image. I am using below command to build native image.

./gradlew clean build -Dquarkus.package.type=native -Dquarkus.native.native-image-xmx=6g 

This native build command is giving below error:

java.lang.UnsupportedOperationException: Add AWT Quarkus extension to enable Java2D/ImageIO. Additional system libraries such as `freetype' and `fontconfig' might be needed.
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:45)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1181)
at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:335)
at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:272)
at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:258)

My build.gradle.

dependencies {
    implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
    implementation enforcedPlatform("${quarkusPlatformGroupId}:quarkus-amazon-services-bom:${quarkusPlatformVersion}")
    implementation 'io.quarkus:quarkus-amazon-lambda'
    implementation 'io.quarkiverse.amazonservices:quarkus-amazon-s3'
    implementation 'io.quarkiverse.amazonservices:quarkus-amazon-sqs'
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
    implementation group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.26'
    implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
    implementation group: 'org.jboss.resteasy', name: 'resteasy-multipart-provider', version: '4.7.5.Final'
    implementation group: 'software.amazon.awssdk', name: 'url-connection-client', version: '2.17.205'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.4'
    implementation 'io.quarkus:quarkus-config-yaml'
}

My application.yml

quarkus:
  native:
    additional-build-args: --initialize-at-run-time=org.apache.pdfbox.pdmodel.encryption.PublicKeySecurityHandler

We also tried after adding implementation 'io.quarkus:quarkus-awt' in build.gradle file and build is getting failed.

build logs after adding 'io.quarkus:quarkus-awt'`

Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.awt.image.ColorConvertOp are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.
com.oracle.graal.pointsto.util.AnalysisError: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.awt.image.ColorConvertOp are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.
        at com.oracle.graal.pointsto.util.AnalysisError.shouldNotReachHere(AnalysisError.java:172)
        at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:66)
        at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$postTask$9(ImageHeapScanner.java:611)
        at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
        at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
        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)
Caused by: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.awt.image.ColorConvertOp are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.
        at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
        at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:64)
        ... 9 more

Can anyone help here to build native with pdfbox or any alternative to create image from pdf using quarkus?

Expected behavior

Build must be completed and runner file will also working for the lambda.

@dilipdhankecha2530 dilipdhankecha2530 added the kind/bug Something isn't working label Jul 12, 2022
@geoand
Copy link
Contributor

geoand commented Jul 13, 2022

I am going to close this as pdfbox is not something we support in native mode.

However if @Karm has some insights here, it would be nice to get them.

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2022
@geoand geoand added triage/wontfix This will not be worked on area/native-image labels Jul 13, 2022
@dilipdhankecha2530
Copy link
Author

@geoand
I just check one quarkus dependency which was used in pdfbox support.
If we are using that library then also not able to create a native build.

org.apache.camel.quarkus:camel-quarkus-pdf

@geoand
Copy link
Contributor

geoand commented Jul 13, 2022

cc @ppalaga @lburgazzoli

@dilipdhankecha2530
Copy link
Author

@geoand
Could you please reopen the same issue.

@geoand
Copy link
Contributor

geoand commented Jul 14, 2022

I want input from the Camel folks before proceeding any further

@ppalaga
Copy link
Contributor

ppalaga commented Jul 14, 2022

Yes, camel-quarkus-pdf is using Apache PDFBox under the hood. It adds some native-image config, but looking at its doc page https://camel.apache.org/components/latest/pdf-component.html it does not look like we support the PDF -> image workflow. You may want to file a Camel issue for that https://issues.apache.org/jira/projects/CAMEL

@dilipdhankecha2530
Copy link
Author

dilipdhankecha2530 commented Jul 19, 2022

@ppalaga

With camel-quarkus-pdf, i am able to generate image from the pdf file.
My reference code is here.
I am able to run the code but while creating the native image it will come up with below error message.

22.1-java11: Pulling from quarkus/ubi-quarkus-native-image
Digest: sha256:04464863cd626543e58f3058e168985b3be0597f55fa3de29c4a48191e89fe1b
Status: Image is up to date for quay.io/quarkus/ubi-quarkus-native-image:22.1-java11
quay.io/quarkus/ubi-quarkus-native-image:22.1-java11
========================================================================================================================
GraalVM Native Image: Generating 'code-with-quarkus-1.0.0-SNAPSHOT-runner' (executable)...
========================================================================================================================
[1/7] Initializing...                                                                                   (16.4s @ 0.30GB)
 Version info: 'GraalVM 22.1.0 Java 11 CE'
 C compiler: gcc (redhat, x86_64, 8.5.0)
 Garbage collector: Serial GC
 4 user-provided feature(s)
  - io.quarkus.awt.runtime.graal.AwtFeature
  - io.quarkus.runner.AutoFeature
  - io.quarkus.runtime.graal.DisableLoggingAutoFeature
  - io.quarkus.runtime.graal.ResourcesFeature
12:03:06,572 WARN  [org.apa.pdf.pdm.fon.FileSystemFontProvider] New fonts found, font cache will be re-built
12:03:06,577 WARN  [org.apa.pdf.pdm.fon.FileSystemFontProvider] Building on-disk font cache, this may take a while
12:03:06,706 WARN  [org.apa.pdf.pdm.fon.FileSystemFontProvider] Finished building on-disk font cache, found 9 fonts
[2/7] Performing analysis...  [*]                                                                       (51.3s @ 4.23GB)
  10,478 (81.87%) of 12,798 classes reachable
  15,560 (68.03%) of 22,872 fields reachable
  57,342 (59.63%) of 96,162 methods reachable
     543 classes,    23 fields, and 3,608 methods registered for reflection

Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.awt.image.ColorConvertOp are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.
com.oracle.graal.pointsto.util.AnalysisError: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.awt.image.ColorConvertOp are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.
        at com.oracle.graal.pointsto.util.AnalysisError.shouldNotReachHere(AnalysisError.java:172)
        at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:66)
        at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$postTask$9(ImageHeapScanner.java:611)
        at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
        at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
        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)
Caused by: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.awt.image.ColorConvertOp are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.
        at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
        at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:64)
        ... 9 more
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.awt.image.ColorConvertOp are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.
        at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.checkImageHeapInstance(ClassInitializationFeature.java:135)
        at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:582)
        at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.replaceObject(AnalysisConstantReflectionProvider.java:257)
------------------------------------------------------------------------------------------------------------------------
        at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.interceptValue(AnalysisConstantReflectionProvider.java:228)
        at com.oracle.svm.hosted.heap.SVMImageHeapScanner.transformFieldValue(SVMImageHeapScanner.java:126)
        at com.oracle.graal.pointsto.heap.ImageHeapScanner.onFieldValueReachable(ImageHeapScanner.java:331)
        at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$createImageHeapObject$3(ImageHeapScanner.java:272)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
        ... 9 more
                        2.7s (3.8% of total time) in 21 GCs | Peak RSS: 4.96GB | CPU load: 6.43
========================================================================================================================
Failed generating 'code-with-quarkus-1.0.0-SNAPSHOT-runner' after 1m 8s.
Error: Image build request failed with exit status 1
> Task :quarkusBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':quarkusBuild'.
> io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: io.quarkus.deployment.pkg.steps.NativeImageBuildStep$ImageGenerationFailureException: Image generation failed. Exit code: 1
        at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.imageGenerationFailed(NativeImageBuildStep.java:400)
        at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:240)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:944)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 17s
6 actionable tasks: 1 executed, 5 up-to-date

Is there any configuration i missed?
could you please help now.

@dilipdhankecha2530
Copy link
Author

@ppalaga @lburgazzoli
Could you pleas help me to out from this camel dependecy with native build?

@ppalaga
Copy link
Contributor

ppalaga commented Aug 2, 2022

Thanks for the example code, @dilipdhankecha2530. You are using PDFBox directly. There is no Camel code in your app. And there is no way to do this with Camel either.
I can thus only help with a general advice to follow the hint mentioned in the error message:

To see how [java.awt.image.ColorConvertOp] got instantiated use --trace-object-instantiation=java.awt.image.ColorConvertOp.

You may want to add it via application.properties:

quarkus.native.additional-build-args = --trace-object-instantiation\=java.awt.image.ColorConvertOp

The output of native-image command should then tell you which class(es) you need to declare as initialized at runtime - see https://quarkus.io/guides/writing-native-applications-tips#delaying-class-initialization

@Karm
Copy link
Member

Karm commented Aug 11, 2022

See
quarkusio/quarkus-quickstarts#1154

for a working example.

@geoand
Copy link
Contributor

geoand commented Sep 13, 2023

@Karm I wanted to do something completely unrelated to work and your quickstart allowed me to get PDFBox working in native! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image kind/bug Something isn't working triage/wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants