From d64ad587eb19e18a2c7df784ad5f12e67291bc0b Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Wed, 23 Apr 2025 21:49:10 +0200 Subject: [PATCH] Use proper classloader for finding SVGRasterizer #1965 #2049 When initializing the SVGFileFormat class for loading SVGs, the current context classloader is used by the ServiceLoader to find an SVGRasterizer implementation. This classloader may be incorrect in some cases, i.e., it may not be the plain system classloader or an according OSGi classloader but, e.g., some specific classloader for test execution. This change makes the ServiceLoader use the same classloader for finding an SVGRasterizer implementation than the classloader of the SVGFileFormat class containing the rasterizer reference itself. Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/1965 Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/2049 --- .../common/org/eclipse/swt/internal/image/SVGFileFormat.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/SVGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/SVGFileFormat.java index 001b9b6828d..78d8abebcb6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/SVGFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/SVGFileFormat.java @@ -31,7 +31,8 @@ public class SVGFileFormat extends FileFormat { /** The instance of the registered {@link SVGRasterizer}. */ - private static final SVGRasterizer RASTERIZER = ServiceLoader.load(SVGRasterizer.class).findFirst().orElse(null); + private static final SVGRasterizer RASTERIZER = ServiceLoader + .load(SVGRasterizer.class, SVGFileFormat.class.getClassLoader()).findFirst().orElse(null); @Override boolean isFileFormat(LEDataInputStream stream) throws IOException {