PDFBOX-4671: don't use ServiceLookup to load the provided default
implementation for caching
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 @@
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();
}
- cacheBridge = cacheBridgeServices.next();
+ else
+ {
+ // use the default implementation
+ cacheBridge = new SoftReferenceCacheBridge();
+ }
}
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);
}
}