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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git


The following commit(s) were added to refs/heads/master by this push:
     new 816923b3 Remove declaration of exceptions never thrown
816923b3 is described below

commit 816923b3a2401dd1765e92e77a3fc4d9a6b0abc4
Author: Thomas Vandahl <[email protected]>
AuthorDate: Fri Sep 4 23:14:05 2026 +0200

    Remove declaration of exceptions never thrown
---
 .../apache/commons/jcs4/admin/JCSAdminBean.java    | 10 +----
 .../jcs4/engine/control/CompositeCache.java        | 24 ++---------
 .../AbstractDoubleLinkedListMemoryCache.java       | 17 ++++----
 .../jcs4/engine/memory/AbstractMemoryCache.java    | 28 +++----------
 .../jcs4/engine/memory/behavior/IMemoryCache.java  | 47 ++++++----------------
 .../memory/soft/SoftReferenceMemoryCache.java      |  4 +-
 .../jcs4/engine/memory/MockMemoryCache.java        |  9 -----
 7 files changed, 32 insertions(+), 107 deletions(-)

diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
index b3409de6..d45d7d62 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
@@ -241,15 +241,7 @@ public class JCSAdminBean implements JCSJMXBean
 
         for (final K key : memCache.getKeySet())
         {
-            ICacheElement<K, V> ice = null;
-                       try
-                       {
-                               ice = memCache.get(key);
-                       }
-                       catch (final IOException e)
-                       {
-                throw new IllegalStateException("IOException while trying to 
get a cached element", e);
-                       }
+            ICacheElement<K, V> ice = memCache.get(key);
 
                        if (ice == null)
                        {
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java
index 4c471d5d..4c279daf 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java
@@ -1192,17 +1192,7 @@ public class CompositeCache<K, V>
     protected boolean remove(final K key, final boolean localOnly)
     {
         removeCount.incrementAndGet();
-
-        boolean removed = false;
-
-        try
-        {
-            removed = memCache.remove(key);
-        }
-        catch (final IOException e)
-        {
-            log.error(e);
-        }
+        boolean removed = memCache.remove(key);
 
         // Removes from all auxiliary caches.
         for (final ICache<K, V> aux : auxCaches)
@@ -1263,16 +1253,8 @@ public class CompositeCache<K, V>
     protected void removeAll(final boolean localOnly)
         throws IOException
     {
-        try
-        {
-            memCache.removeAll();
-
-            log.debug("Removed All keys from the memory cache.");
-        }
-        catch (final IOException ex)
-        {
-            log.error("Trouble updating memory cache.", ex);
-        }
+        memCache.removeAll();
+        log.debug("Removed All keys from the memory cache.");
 
         // Removes from all auxiliary disk caches.
         auxCaches.stream()
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java
index 848db553..57ff21aa 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java
@@ -114,7 +114,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
      * @see 
org.apache.commons.jcs4.engine.memory.AbstractMemoryCache#get(Object)
      */
     @Override
-    public ICacheElement<K, V> get(final K key) throws IOException
+    public ICacheElement<K, V> get(final K key)
     {
         final ICacheElement<K, V> ce = super.get(key);
 
@@ -311,7 +311,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
                 throw new Error("update: last.ce is null!");
             }
             waterfall(toSpool);
-            if (map.remove(toSpool.key()) == null)
+            if (!remove(toSpool.key()))
             {
                 log.warn("update: remove failed for key: {0}", toSpool::key);
 
@@ -320,8 +320,6 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
                     verifyCache();
                 }
             }
-
-            list.remove(last);
         }
 
         return toSpool;
@@ -347,6 +345,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
     private void verifyCache()
     {
         boolean found = false;
+        Map<K, MemoryElementDescriptor<K, V>> mapView = getMapView();
         log.trace("verifycache[{0}]: map contains {1} elements, linked list "
                 + "contains {2} elements", getCacheName(), getSize(),
                 list.size());
@@ -354,7 +353,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
         for (MemoryElementDescriptor<K, V> li = list.getFirst(); li != null; 
li = (MemoryElementDescriptor<K, V>) li.next)
         {
             final K key = li.getCacheElement().key();
-            if (!map.containsKey(key))
+            if (!mapView.containsKey(key))
             {
                 log.error("verifycache[{0}]: map does not contain key : {1}",
                         getCacheName(), key);
@@ -370,7 +369,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
                 }
                 dumpMap();
             }
-            else if (map.get(key) == null)
+            else if (mapView.get(key) == null)
             {
                 log.error("verifycache[{0}]: linked list retrieval returned "
                         + "null for key: {1}", getCacheName(), key);
@@ -380,7 +379,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
         log.trace("verifycache: checking linked list by value ");
         for (MemoryElementDescriptor<K, V> li = list.getFirst(); li != null; 
li = (MemoryElementDescriptor<K, V>) li.next)
         {
-            if (!map.containsValue(li))
+            if (!mapView.containsValue(li))
             {
                 log.error("verifycache[{0}]: map does not contain value: {1}",
                         getCacheName(), li);
@@ -389,7 +388,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
         }
 
         log.trace("verifycache: checking via keysets!");
-        for (final Object val : map.keySet())
+        for (final Object val : mapView.keySet())
         {
             found = false;
 
@@ -406,7 +405,7 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
                 log.error("verifycache[{0}]: key not found in list : {1}",
                         getCacheName(), val);
                 dumpCacheEntries();
-                if (map.containsKey(val))
+                if (mapView.containsKey(val))
                 {
                     log.error("verifycache: map contains key");
                 }
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java
index 1421f5c3..8b871784 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java
@@ -68,7 +68,7 @@ public abstract class AbstractMemoryCache<K, V>
     protected final ReadWriteLock lock = new ReentrantReadWriteLock();
 
     /** Map where items are stored by key.  This is created by the concrete 
child class. */
-    protected Map<K, MemoryElementDescriptor<K, V>> map; // TODO privatise
+    private Map<K, MemoryElementDescriptor<K, V>> map;
 
     /** Number of hits */
     private AtomicLong hitCnt;
@@ -153,14 +153,12 @@ public abstract class AbstractMemoryCache<K, V>
 
     /**
      * Gets an item from the cache.
-     * <p>
      *
      * @param key Identifies item to find
      * @return ICacheElement&lt;K, V&gt; if found, else null
-     * @throws IOException
      */
     @Override
-    public ICacheElement<K, V> get(final K key) throws IOException
+    public ICacheElement<K, V> get(final K key)
     {
         ICacheElement<K, V> ce = null;
 
@@ -243,25 +241,14 @@ public abstract class AbstractMemoryCache<K, V>
      * @param keys
      * @return A map of K key to ICacheElement&lt;K, V&gt; element, or an 
empty map if there is no
      *         data in cache for any of these keys
-     * @throws IOException
      */
     @Override
     public Map<K, ICacheElement<K, V>> getMultiple(final Set<K> keys)
-        throws IOException
     {
         if (keys != null)
         {
             return keys.stream()
-                .map(key -> {
-                    try
-                    {
-                        return get(key);
-                    }
-                    catch (final IOException e)
-                    {
-                        return null;
-                    }
-                })
+                .map(key -> get(key))
                 .filter(Objects::nonNull)
                 .collect(Collectors.toMap(
                         ICacheElement::key,
@@ -277,11 +264,9 @@ public abstract class AbstractMemoryCache<K, V>
      *
      * @param key Identifies item to find
      * @return Element matching key if found, or null
-     * @throws IOException
      */
     @Override
     public ICacheElement<K, V> getQuiet( final K key )
-        throws IOException
     {
         ICacheElement<K, V> ce = null;
 
@@ -419,10 +404,9 @@ public abstract class AbstractMemoryCache<K, V>
      *
      * @param key
      * @return true if the removal was successful
-     * @throws IOException
      */
     @Override
-    public boolean remove(final K key) throws IOException
+    public boolean remove(final K key)
     {
         log.debug("removing item for key: {0}", key);
 
@@ -461,11 +445,9 @@ public abstract class AbstractMemoryCache<K, V>
 
     /**
      * Removes all cached items from the cache.
-     *
-     * @throws IOException
      */
     @Override
-    public void removeAll() throws IOException
+    public void removeAll()
     {
         lock.writeLock().lock();
         try
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java
index fd51976e..cff00e40 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java
@@ -56,14 +56,10 @@ public interface IMemoryCache<K, V>
     /**
      * Gets an item from the cache
      *
-     * @param key
-     *            Description of the Parameter
-     * @return Description of the Return Value
-     * @throws IOException
-     *                Description of the Exception
+     * @param key Identifies item to find
+     * @return ICacheElement&lt;K, V&gt; if found, else null
      */
-    ICacheElement<K, V> get( K key )
-        throws IOException;
+    ICacheElement<K, V> get(K key);
 
     /**
      * Returns the CacheAttributes for the region.
@@ -88,10 +84,8 @@ public interface IMemoryCache<K, V>
      * @param keys
      * @return A map of K key to ICacheElement&lt;K, V&gt; element, or an 
empty map
      * if there is no data in cache for any of these keys
-     * @throws IOException
      */
-    Map<K, ICacheElement<K, V>> getMultiple( Set<K> keys )
-        throws IOException;
+    Map<K, ICacheElement<K, V>> getMultiple(Set<K> keys);
 
     /**
      * Gets an item from the cache without effecting its order or last access
@@ -100,11 +94,8 @@ public interface IMemoryCache<K, V>
      * @param key
      *            Description of the Parameter
      * @return The quiet value
-     * @throws IOException
-     *                Description of the Exception
      */
-    ICacheElement<K, V> getQuiet( K key )
-        throws IOException;
+    ICacheElement<K, V> getQuiet(K key);
 
     /**
      * Gets the number of elements contained in the memory store
@@ -130,31 +121,21 @@ public interface IMemoryCache<K, V>
     /**
      * Removes an item from the cache
      *
-     * @param key
-     *            Identifies item to be removed
-     * @return Description of the Return Value
-     * @throws IOException
-     *                Description of the Exception
+     * @param key Identifies item to be removed
+     * @return true if the removal was successful
      */
-    boolean remove( K key )
-        throws IOException;
+    boolean remove(K key);
 
     /**
      * Removes all cached items from the cache.
-     *
-     * @throws IOException
-     *                Description of the Exception
      */
-    void removeAll()
-        throws IOException;
+    void removeAll();
 
     /**
      * Puts an item to the cache.
      *
-     * @param ce
-     *            Description of the Parameter
-     * @throws IOException
-     *                Description of the Exception
+     * @param ce the cache item
+     * @throws IOException if the update operation fails
      */
     void update( ICacheElement<K, V> ce )
         throws IOException;
@@ -162,10 +143,8 @@ public interface IMemoryCache<K, V>
     /**
      * Spools the item contained in the provided element to disk
      *
-     * @param ce
-     *            Description of the Parameter
-     * @throws IOException
-     *                Description of the Exception
+     * @param ce the cache item
+     * @throws IOException if the spool operation fails
      */
     void waterfall( ICacheElement<K, V> ce )
         throws IOException;
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java
index 22c32296..67515a1a 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java
@@ -78,7 +78,7 @@ public class SoftReferenceMemoryCache<K, V> extends 
AbstractMemoryCache<K, V>
         lock.readLock().lock();
         try
         {
-            return map.entrySet().stream()
+            return getMapView().entrySet().stream()
                     .filter(e -> e.getValue().getCacheElement() != null)
                     .map(e -> e.getKey())
                     .collect(Collectors.toSet());
@@ -100,7 +100,7 @@ public class SoftReferenceMemoryCache<K, V> extends 
AbstractMemoryCache<K, V>
         lock.readLock().lock();
         try
         {
-            long size = map.values().stream()
+            long size = getMapView().values().stream()
                     .filter(v -> v.getCacheElement() != null)
                     .count();
 
diff --git 
a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java
 
b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java
index 17bcbb7e..39cbe6ca 100644
--- 
a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java
+++ 
b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java
@@ -77,11 +77,9 @@ public class MockMemoryCache<K, V>
     /**
      * @param key
      * @return (ICacheElement) map.get( key )
-     * @throws IOException
      */
     @Override
     public ICacheElement<K, V> get( final K key )
-        throws IOException
     {
         return map.get( key );
     }
@@ -106,11 +104,9 @@ public class MockMemoryCache<K, V>
     /**
      * @param keys
      * @return elements
-     * @throws IOException
      */
     @Override
     public Map<K, ICacheElement<K, V>> getMultiple(final Set<K> keys)
-        throws IOException
     {
         final Map<K, ICacheElement<K, V>> elements = new HashMap<>();
 
@@ -132,11 +128,9 @@ public class MockMemoryCache<K, V>
     /**
      * @param key
      * @return (ICacheElement) map.get( key )
-     * @throws IOException
      */
     @Override
     public ICacheElement<K, V> getQuiet( final K key )
-        throws IOException
     {
         return map.get( key );
     }
@@ -168,11 +162,9 @@ public class MockMemoryCache<K, V>
     /**
      * @param key
      * @return map.remove( key ) != null
-     * @throws IOException
      */
     @Override
     public boolean remove( final K key )
-        throws IOException
     {
         return map.remove( key ) != null;
     }
@@ -182,7 +174,6 @@ public class MockMemoryCache<K, V>
      */
     @Override
     public void removeAll()
-        throws IOException
     {
         map.clear();
     }

Reply via email to