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

Avoid ICC_ColorSpace instances in Apache Tika to support GraalVM 20.3 #13718

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceDirectoryBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.tika.TikaParseException;
import io.quarkus.tika.runtime.TikaConfiguration;
Expand Down Expand Up @@ -68,10 +69,17 @@ FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.TIKA);
}

@BuildStep
public void registerRuntimeInitializedClasses(BuildProducer<RuntimeInitializedClassBuildItem> resource) {
//org.apache.tika.parser.pdf.PDFParser (https://issues.apache.org/jira/browse/PDFBOX-4548)
resource.produce(new RuntimeInitializedClassBuildItem("org.apache.pdfbox.pdmodel.font.PDType1Font"));
@BuildStep(onlyIf = NativeBuild.class)
List<RuntimeInitializedClassBuildItem> runtimeInitImageIOClasses() {
return Arrays.asList(
//org.apache.tika.parser.pdf.PDFParser (https://issues.apache.org/jira/browse/PDFBOX-4548)
new RuntimeInitializedClassBuildItem("org.apache.pdfbox.pdmodel.font.PDType1Font"),
// The following classes hold instances of java.awt.color.ICC_ColorSpace that are not allowed in the
// image heap as this class should be initialized at image runtime
// See https://github.com/quarkusio/quarkus/pull/13644
new RuntimeInitializedClassBuildItem("org.apache.pdfbox.rendering.SoftMask"),
new RuntimeInitializedClassBuildItem(
"org.apache.pdfbox.pdmodel.graphics.color.PDCIEDictionaryBasedColorSpace"));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.tika.graalvm;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks great, thanks!

Minor nitpick: this class should be in the io.quarkus.tika.runtime.graal to be consistent with other extensions.


import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

@TargetClass(className = "org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB")
final class Target_org_apache_pdfbox_pdmodel_graphics_color_PDDeviceRGB {
@Substitute
private void init() {
// This method appears to be just a workaround for PDFBOX-2184
}

// awtColorSpace is not actually used in PDDeviceRGB
@Alias
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)
private volatile ColorSpace awtColorSpace;
}

@TargetClass(className = "org.apache.pdfbox.pdmodel.graphics.color.PDICCBased")
final class Target_org_apache_pdfbox_pdmodel_graphics_color_PDICCBased {
// This class provides alternative paths for when awtColorSpace is null, so it is safe to reset it
@Alias
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)
private volatile ICC_ColorSpace awtColorSpace;
}

// Substitutions to prevent ICC_ColorSpace instances from appearing in the native image when using Apache Tika
// See https://github.com/quarkusio/quarkus/pull/13644
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a comment adding that this class should be removed once we switch from GraalVM 20.3 to GraalVM 21?

(having 20.3 in the comment is important, this way I will catch it when upgrading from 20.3 as I will look for 20.3 occurrences everywhere)

class PDFBoxSubstitutions {

}