This is an automated email from the ASF dual-hosted git repository.

lehmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pdfbox-jbig2.git


The following commit(s) were added to refs/heads/master by this push:
     new f955ac6  PDFBOX-4671: don't use ServiceLookup to load the provided 
default implementation for caching
f955ac6 is described below

commit f955ac656ea8acd98a43f8fda5a97d8515211781
Author: Andreas Lehmkühler <[email protected]>
AuthorDate: Fri Jan 14 14:05:31 2022 +0100

    PDFBOX-4671: don't use ServiceLookup to load the provided default
    implementation for caching
---
 .../apache/pdfbox/jbig2/util/cache/CacheFactory.java   | 11 +++++++----
 .../org.apache.pdfbox.jbig2.util.cache.CacheBridge     | 18 ------------------
 .../org/apache/pdfbox/jbig2/util/CacheFactoryTest.java | 16 ++++------------
 3 files changed, 11 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/apache/pdfbox/jbig2/util/cache/CacheFactory.java 
b/src/main/java/org/apache/pdfbox/jbig2/util/cache/CacheFactory.java
index a39d37e..f4f18b7 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/util/cache/CacheFactory.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/util/cache/CacheFactory.java
@@ -39,12 +39,15 @@ public class CacheFactory
             final Iterator<CacheBridge> cacheBridgeServices = serviceLookup
                     .getServices(CacheBridge.class, clsLoader);
 
-            if (!cacheBridgeServices.hasNext())
+            if (cacheBridgeServices.hasNext())
             {
-                throw new IllegalStateException("No implementation of " + 
CacheBridge.class
-                        + " was avaliable using META-INF/services lookup");
+                cacheBridge = cacheBridgeServices.next();
+            }
+            else
+            {
+                // use the default implementation
+                cacheBridge = new SoftReferenceCacheBridge(); 
             }
-            cacheBridge = cacheBridgeServices.next();
         }
         return cacheBridge.getCache();
     }
diff --git 
a/src/main/resources/META-INF/services/org.apache.pdfbox.jbig2.util.cache.CacheBridge
 
b/src/main/resources/META-INF/services/org.apache.pdfbox.jbig2.util.cache.CacheBridge
deleted file mode 100644
index fa9ad12..0000000
--- 
a/src/main/resources/META-INF/services/org.apache.pdfbox.jbig2.util.cache.CacheBridge
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.pdfbox.jbig2.util.cache.SoftReferenceCacheBridge
\ No newline at end of file
diff --git a/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java 
b/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java
index 0a9e980..599820e 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/util/CacheFactoryTest.java
@@ -17,27 +17,19 @@
 
 package org.apache.pdfbox.jbig2.util;
 
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
-import org.apache.pdfbox.jbig2.util.cache.CacheBridge;
 import org.apache.pdfbox.jbig2.util.cache.CacheFactory;
+import org.apache.pdfbox.jbig2.util.cache.SoftReferenceCache;
 import org.junit.Test;
 
 public class CacheFactoryTest
 {
 
     @Test
-    public void testWithDefaultClassLoader()
+    public void testWithDefaultImplementation()
     {
-        CacheFactory.setClassLoader(CacheBridge.class.getClassLoader());
-        assertNotNull(CacheFactory.getCache());
-    }
-
-    @Test
-    public void testWithContextClassLoader()
-    {
-        
CacheFactory.setClassLoader(Thread.currentThread().getContextClassLoader());
-        assertNotNull(CacheFactory.getCache());
+        assertTrue(CacheFactory.getCache() instanceof SoftReferenceCache);
     }
 
 }

Reply via email to