You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2024/04/03 07:49:41 UTC
(xmlgraphics-commons) branch main updated: XGC-141: Do not use a singleton for ImageImplRegistry
This is an automated email from the ASF dual-hosted git repository.
ssteiner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-commons.git
The following commit(s) were added to refs/heads/main by this push:
new 95b17e2 XGC-141: Do not use a singleton for ImageImplRegistry
95b17e2 is described below
commit 95b17e2c6508db33a51a4a0a0ab36dcd82ba5d8e
Author: Simon Steiner <ss...@apache.org>
AuthorDate: Wed Apr 3 08:49:28 2024 +0100
XGC-141: Do not use a singleton for ImageImplRegistry
---
.../java/org/apache/xmlgraphics/image/loader/ImageManager.java | 2 +-
.../apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java | 7 ++-----
.../apache/xmlgraphics/image/loader/ImageLoaderTestCase.java | 10 +++++++++-
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java b/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java
index 2aefbb9..d6eaca0 100644
--- a/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java
+++ b/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java
@@ -61,7 +61,7 @@ public class ImageManager {
* @param context the session-independent context information
*/
public ImageManager(ImageContext context) {
- this(ImageImplRegistry.getDefaultInstance(), context);
+ this(ImageImplRegistry.newInstance(), context);
}
/**
diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java b/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java
index 56a6cef..36041c3 100644
--- a/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java
+++ b/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java
@@ -69,9 +69,6 @@ public class ImageImplRegistry {
private Map additionalPenalties = new java.util.HashMap(); //<String, Penalty>
//Note: String as key chosen to avoid possible class-unloading leaks
- /** Singleton instance */
- private static ImageImplRegistry defaultInstance = new ImageImplRegistry();
-
/**
* Main constructor. This constructor allows to disable plug-in discovery for testing purposes.
* @param discover true if implementation classes shall automatically be discovered.
@@ -93,8 +90,8 @@ public class ImageImplRegistry {
* Returns the default instance of the Image implementation registry.
* @return the default instance
*/
- public static ImageImplRegistry getDefaultInstance() {
- return defaultInstance;
+ public static ImageImplRegistry newInstance() {
+ return new ImageImplRegistry();
}
/**
diff --git a/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java b/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java
index 095cfd5..df46ce4 100644
--- a/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java
+++ b/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java
@@ -31,6 +31,7 @@ import javax.imageio.stream.ImageInputStream;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
+import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -192,7 +193,7 @@ public class ImageLoaderTestCase {
private void runReaders(List<ICC_Profile> profiles, ImageSessionContext isc, String uri,
String mime, ImageFlavor rawFlavor) throws Exception {
- ImageLoaderFactory[] ilfs = ImageImplRegistry.getDefaultInstance()
+ ImageLoaderFactory[] ilfs = ImageImplRegistry.newInstance()
.getImageLoaderFactories(mime);
if (ilfs != null) {
for (int i = 0; i < ilfs.length; i++) {
@@ -248,6 +249,13 @@ public class ImageLoaderTestCase {
sessionContext.checkAllStreamsClosed();
}
+ @Test
+ public void testRegistry() {
+ ImageManager im1 = new ImageManager(imageContext);
+ ImageManager im2 = new ImageManager(imageContext);
+ Assert.assertNotSame(im1.getRegistry(), im2.getRegistry());
+ }
+
private static class MyImageSessionContext extends MockImageSessionContext {
private List streams = new java.util.ArrayList();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org