Skip to content

Commit 79f33c0

Browse files
committed
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 SVGRasterizer class itself. Fixes #1965 Fixes #2049
1 parent d4caabf commit 79f33c0

File tree

1 file changed

+5
-1
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image

1 file changed

+5
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/SVGFileFormat.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
public class SVGFileFormat extends FileFormat {
3232

3333
/** The instance of the registered {@link SVGRasterizer}. */
34-
private static final SVGRasterizer RASTERIZER = ServiceLoader.load(SVGRasterizer.class).findFirst().orElse(null);
34+
// The service loader uses the classloader of the SVGRasterizer class to avoid
35+
// that a potentially non-fitting context classloader is used for searching for
36+
// a rasterizer implementation (such as during test execution).
37+
private static final SVGRasterizer RASTERIZER = ServiceLoader
38+
.load(SVGRasterizer.class, SVGRasterizer.class.getClassLoader()).findFirst().orElse(null);
3539

3640
@Override
3741
boolean isFileFormat(LEDataInputStream stream) throws IOException {

0 commit comments

Comments
 (0)