This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit 6b6b54b7b13299dd8435c7fc9b21df7efbd25d80 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Mar 5 14:31:17 2021 -0500 No need to nest in else. --- .../apache/commons/jcs3/admin/JCSAdminBean.java | 8 +--- .../auxiliary/disk/block/BlockDiskKeyStore.java | 20 ++++----- .../auxiliary/disk/indexed/IndexedDiskCache.java | 12 ++---- .../disk/indexed/IndexedDiskElementDescriptor.java | 16 +++----- .../socket/tcp/LateralTCPDiscoveryListener.java | 26 +++++------- .../lateral/socket/tcp/LateralTCPListener.java | 7 +--- .../lateral/socket/tcp/LateralTCPService.java | 35 +++++++--------- .../remote/RemoteCacheFailoverRunner.java | 2 +- .../jcs3/auxiliary/remote/RemoteLocation.java | 5 +-- .../remote/http/server/RemoteHttpCacheService.java | 15 ++----- .../commons/jcs3/engine/PooledCacheEventQueue.java | 5 +-- .../jcs3/engine/control/CompositeCache.java | 45 ++++++++------------ .../jcs3/engine/control/CompositeCacheManager.java | 7 +--- .../AbstractDoubleLinkedListMemoryCache.java | 22 ++++------ .../jcs3/engine/memory/lru/LHMLRUMemoryCache.java | 11 ++--- .../commons/jcs3/utils/config/PropertySetter.java | 8 ++-- .../commons/jcs3/utils/net/HostNameUtil.java | 2 +- .../serialization/SerializationConversionUtil.java | 48 +++++++++------------- .../commons/jcs3/utils/struct/AbstractLRUMap.java | 20 ++++----- .../jcs3/auxiliary/disk/DiskTestObject.java | 3 +- .../jcache/openjpa/OpenJPAJCacheDataCache.java | 5 +-- .../org/apache/commons/jcs3/jcache/JCSCache.java | 10 ++--- .../commons/jcs3/jcache/JCSCachingManager.java | 20 ++++----- 23 files changed, 132 insertions(+), 220 deletions(-) diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/admin/JCSAdminBean.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/admin/JCSAdminBean.java index 4535925..617801f 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/admin/JCSAdminBean.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/admin/JCSAdminBean.java @@ -359,15 +359,11 @@ public class JCSAdminBean implements JCSJMXBean { if (keyInCache.toString().equals(key)) { - if (keyToRemove == null) - { - keyToRemove = keyInCache; - } - else - { + if (keyToRemove != null) { // A key matching the one specified was already found... throw new IllegalStateException("Unexpectedly found duplicate keys in the cache region matching the key specified."); } + keyToRemove = keyInCache; } } if (keyToRemove == null) diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java index 37fee57..fe86175 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java @@ -541,21 +541,17 @@ public class BlockDiskKeyStore<K> } } boolean ok = true; - if (log.isTraceEnabled()) - { - for (final Entry<Integer, Set<K>> e : blockAllocationMap.entrySet()) - { - log.trace("Block {0}: {1}", e.getKey(), e.getValue()); - if (e.getValue().size() > 1) - { - ok = false; - } - } + if (!log.isTraceEnabled()) { return ok; } - else + for (final Entry<Integer, Set<K>> e : blockAllocationMap.entrySet()) { - return ok; + log.trace("Block {0}: {1}", e.getKey(), e.getValue()); + if (e.getValue().size() > 1) + { + ok = false; + } } + return ok; } } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java index 4866b43..4259df4 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java @@ -410,10 +410,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V> isOk = false; break; } - else - { - expectedNextPos = ded.pos + IndexedDisk.HEADER_SIZE_BYTES + ded.len; - } + expectedNextPos = ded.pos + IndexedDisk.HEADER_SIZE_BYTES + ded.len; } log.debug("{0}: Check for DED overlaps took {1} ms.", () -> logCacheName, () -> timer.getElapsedTime()); @@ -1506,14 +1503,11 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V> { return -1; } - else if (ded1.pos == ded2.pos) + if (ded1.pos == ded2.pos) { return 0; } - else - { - return 1; - } + return 1; } } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java index 4ab8691..1a289cd 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java @@ -82,7 +82,7 @@ public class IndexedDiskElementDescriptor { return false; } - else if (o instanceof IndexedDiskElementDescriptor) + if (o instanceof IndexedDiskElementDescriptor) { final IndexedDiskElementDescriptor ided = (IndexedDiskElementDescriptor)o; return pos == ided.pos && len == ided.len; @@ -111,22 +111,16 @@ public class IndexedDiskElementDescriptor { return 0; } - else if ( o.pos < pos ) + if ( o.pos < pos ) { return -1; } - else - { - return 1; - } + return 1; } - else if ( o.len > len ) + if ( o.len > len ) { return -1; } - else - { - return 1; - } + return 1; } } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java index 131efec..d1fe541 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java @@ -159,16 +159,13 @@ public class LateralTCPDiscoveryListener log.debug( "Called addNoWait, isNew = {0}", isNew ); return isNew; } - else + if ( knownDifferentlyConfiguredRegions.addIfAbsent( noWait.getCacheName() ) ) { - if ( knownDifferentlyConfiguredRegions.addIfAbsent( noWait.getCacheName() ) ) - { - log.info( "addNoWait > Different nodes are configured differently " - + "or region [{0}] is not yet used on this side.", - () -> noWait.getCacheName() ); - } - return false; + log.info( "addNoWait > Different nodes are configured differently " + + "or region [{0}] is not yet used on this side.", + () -> noWait.getCacheName() ); } + return false; } /** @@ -192,16 +189,13 @@ public class LateralTCPDiscoveryListener log.debug( "Called removeNoWait, removed {0}", removed ); return removed; } - else + if ( knownDifferentlyConfiguredRegions.addIfAbsent( noWait.getCacheName() ) ) { - if ( knownDifferentlyConfiguredRegions.addIfAbsent( noWait.getCacheName() ) ) - { - log.info( "addNoWait > Different nodes are configured differently " - + "or region [{0}] is not yet used on this side.", - () -> noWait.getCacheName() ); - } - return false; + log.info( "addNoWait > Different nodes are configured differently " + + "or region [{0}] is not yet used on this side.", + () -> noWait.getCacheName() ); } + return false; } /** diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java index 831ef53..a741ae2 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java @@ -610,11 +610,8 @@ public class LateralTCPListener<K, V> led.valHashCode, led ); return; } - else - { - log.debug( "Different hashcodes, in cache [{0}] sent [{1}]", - test.getVal().hashCode(), led.valHashCode ); - } + log.debug( "Different hashcodes, in cache [{0}] sent [{1}]", + test.getVal().hashCode(), led.valHashCode ); } } handleRemove( cacheName, key ); diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPService.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPService.java index 36a7c64..e7ecd90 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPService.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPService.java @@ -234,11 +234,8 @@ public class LateralTCPService<K, V> ICacheElement<K, V> response = (ICacheElement<K, V>)sender.sendAndReceive( led ); return response; } - else - { - // nothing needs to be done - return null; - } + // nothing needs to be done + return null; } /** @@ -273,25 +270,21 @@ public class LateralTCPService<K, V> throws IOException { // if get is not allowed return - if ( this.allowGet ) - { - final CacheElement<String, String> ce = new CacheElement<>( cacheName, pattern, null ); - final LateralElementDescriptor<String, String> led = new LateralElementDescriptor<>( ce ); - // led.requesterId = requesterId; // later - led.command = LateralCommand.GET_MATCHING; - - final Object response = sender.sendAndReceive( led ); - if ( response != null ) - { - return (Map<K, ICacheElement<K, V>>) response; - } - return Collections.emptyMap(); - } - else - { + if ( !this.allowGet ) { // nothing needs to be done return null; } + final CacheElement<String, String> ce = new CacheElement<>( cacheName, pattern, null ); + final LateralElementDescriptor<String, String> led = new LateralElementDescriptor<>( ce ); + // led.requesterId = requesterId; // later + led.command = LateralCommand.GET_MATCHING; + + final Object response = sender.sendAndReceive( led ); + if ( response != null ) + { + return (Map<K, ICacheElement<K, V>>) response; + } + return Collections.emptyMap(); } /** diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java index 04f5a91..5d07111 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java @@ -154,7 +154,7 @@ public class RemoteCacheFailoverRunner<K, V> extends AbstractAuxiliaryCacheMonit log.warn( "Remote is misconfigured, failovers was null." ); return; } - else if ( failovers.size() == 1 ) + if ( failovers.size() == 1 ) { // if there is only the primary, return out of this log.info( "No failovers defined, exiting failover runner." ); diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteLocation.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteLocation.java index cf41990..00f07c7 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteLocation.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteLocation.java @@ -134,10 +134,7 @@ public final class RemoteLocation final RemoteLocation location = new RemoteLocation( match.group(1), Integer.parseInt( match.group(2) ) ); return location; } - else - { - log.error("Invalid server descriptor: {0}", server); - } + log.error("Invalid server descriptor: {0}", server); return null; } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheService.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheService.java index 0888ee9..33fb8d1 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheService.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheService.java @@ -82,10 +82,7 @@ public class RemoteHttpCacheService<K, V> { return cache.localGet( key ); } - else - { - return cache.get( key ); - } + return cache.get( key ); } /** @@ -111,10 +108,7 @@ public class RemoteHttpCacheService<K, V> { return cache.localGetMultiple( keys ); } - else - { - return cache.getMultiple( keys ); - } + return cache.getMultiple( keys ); } /** @@ -140,10 +134,7 @@ public class RemoteHttpCacheService<K, V> { return cache.localGetMatching( pattern ); } - else - { - return cache.getMatching( pattern ); - } + return cache.getMatching( pattern ); } /** diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java index 5460ca7..bbcebdc 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java @@ -183,9 +183,6 @@ public class PooledCacheEventQueue<K, V> { return 0; } - else - { - return queue.size(); - } + return queue.size(); } } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java index 70d9b6f..06e07da 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java @@ -278,7 +278,7 @@ public class CompositeCache<K, V> throw new IllegalArgumentException("key must not end with " + NAME_COMPONENT_DELIMITER + " for a put operation"); } - else if (cacheElement.getKey() instanceof GroupId) + if (cacheElement.getKey() instanceof GroupId) { throw new IllegalArgumentException("key cannot be a GroupId " + " for a put operation"); } @@ -698,14 +698,11 @@ public class CompositeCache<K, V> doExpires(element); return true; } - else - { - log.debug("{0} - Memory cache hit", () -> cacheAttr.getCacheName()); + log.debug("{0} - Memory cache hit", () -> cacheAttr.getCacheName()); - // Update counters - hitCountRam.incrementAndGet(); - return false; - } + // Update counters + hitCountRam.incrementAndGet(); + return false; }); return elementsFromMemory; @@ -756,10 +753,7 @@ public class CompositeCache<K, V> { break; } - else - { - remainingKeys = pruneKeysFound(keys, elements); - } + remainingKeys = pruneKeysFound(keys, elements); } return elements; @@ -926,22 +920,19 @@ public class CompositeCache<K, V> doExpires(element); return true; } - else - { - log.debug("{0} - Aux cache[{1}] hit.", - () -> cacheAttr.getCacheName(), () -> aux.getCacheName()); + log.debug("{0} - Aux cache[{1}] hit.", + () -> cacheAttr.getCacheName(), () -> aux.getCacheName()); - // Update counters - hitCountAux.incrementAndGet(); - try - { - copyAuxiliaryRetrievedItemToMemory(element); - } - catch (final IOException e) - { - log.error("{0} failed to copy element to memory {1}", - cacheAttr.getCacheName(), element, e); - } + // Update counters + hitCountAux.incrementAndGet(); + try + { + copyAuxiliaryRetrievedItemToMemory(element); + } + catch (final IOException e) + { + log.error("{0} failed to copy element to memory {1}", + cacheAttr.getCacheName(), element, e); } } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCacheManager.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCacheManager.java index beaccd4..fd15d53 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCacheManager.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCacheManager.java @@ -395,11 +395,8 @@ public class CompositeCacheManager + "Force reconfiguration is false. Doing nothing" ); return; } - else - { - log.info( "Configure called after the manager has been configured. " - + "Force reconfiguration is true. Reconfiguring as best we can." ); - } + log.info( "Configure called after the manager has been configured. " + + "Force reconfiguration is true. Reconfiguring as best we can." ); } if ( useSystemProperties ) { diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/AbstractDoubleLinkedListMemoryCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/AbstractDoubleLinkedListMemoryCache.java index ca533ff..579a2c6 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/AbstractDoubleLinkedListMemoryCache.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/AbstractDoubleLinkedListMemoryCache.java @@ -232,23 +232,19 @@ public abstract class AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract if (last != null) { toSpool = last.getCacheElement(); - if (toSpool != null) + if (toSpool == null) { + throw new Error("update: last.ce is null!"); + } + getCompositeCache().spoolToDisk(toSpool); + if (map.remove(toSpool.getKey()) == null) { - getCompositeCache().spoolToDisk(toSpool); - if (map.remove(toSpool.getKey()) == null) - { - log.warn("update: remove failed for key: {0}", toSpool.getKey()); + log.warn("update: remove failed for key: {0}", toSpool.getKey()); - if (log.isTraceEnabled()) - { - verifyCache(); - } + if (log.isTraceEnabled()) + { + verifyCache(); } } - else - { - throw new Error("update: last.ce is null!"); - } list.remove(last); } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/lru/LHMLRUMemoryCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/lru/LHMLRUMemoryCache.java index df9ed8c..6bc9877 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/lru/LHMLRUMemoryCache.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/memory/lru/LHMLRUMemoryCache.java @@ -187,15 +187,12 @@ public class LHMLRUMemoryCache<K, V> { return false; } - else - { - log.debug( "LHMLRU max size: {0}. Spooling element, key: {1}", - () -> getCacheAttributes().getMaxObjects(), () -> element.getKey() ); + log.debug( "LHMLRU max size: {0}. Spooling element, key: {1}", + () -> getCacheAttributes().getMaxObjects(), () -> element.getKey() ); - waterfal( element ); + waterfal( element ); - log.debug( "LHMLRU size: {0}", () -> map.size() ); - } + log.debug( "LHMLRU size: {0}", () -> map.size() ); return true; } } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java index bd26f5a..1578843 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java @@ -239,21 +239,21 @@ public class PropertySetter { return val; } - else if ( Integer.TYPE.isAssignableFrom( type ) ) + if ( Integer.TYPE.isAssignableFrom( type ) ) { return Integer.valueOf( v ); } - else if ( Long.TYPE.isAssignableFrom( type ) ) + if ( Long.TYPE.isAssignableFrom( type ) ) { return Long.valueOf( v ); } - else if ( Boolean.TYPE.isAssignableFrom( type ) ) + if ( Boolean.TYPE.isAssignableFrom( type ) ) { if ( "true".equalsIgnoreCase( v ) ) { return Boolean.TRUE; } - else if ( "false".equalsIgnoreCase( v ) ) + if ( "false".equalsIgnoreCase( v ) ) { return Boolean.FALSE; } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java index 8410a2d..03165ee 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java @@ -128,7 +128,7 @@ public class HostNameUtil // Found non-loopback site-local address. Return it immediately... return inetAddr; } - else if ( candidateAddress == null ) + if ( candidateAddress == null ) { // Found non-loopback address, but not necessarily site-local. // Store it as a candidate to be returned if site-local address is not subsequently found... diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java index f62a7de..2f3707d 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java @@ -67,25 +67,21 @@ public class SerializationConversionUtil } else { - if ( elementSerializer != null ) + if ( elementSerializer == null ) { + // we could just use the default. + throw new IOException( "Could not serialize object. The ElementSerializer is null." ); + } + try { - try - { - serializedValue = elementSerializer.serialize(element.getVal()); + serializedValue = elementSerializer.serialize(element.getVal()); - // update size in bytes - element.getElementAttributes().setSize(serializedValue.length); - } - catch ( final IOException e ) - { - log.error( "Problem serializing object.", e ); - throw e; - } + // update size in bytes + element.getElementAttributes().setSize(serializedValue.length); } - else + catch ( final IOException e ) { - // we could just use the default. - throw new IOException( "Could not serialize object. The ElementSerializer is null." ); + log.error( "Problem serializing object.", e ); + throw e; } } final ICacheElementSerialized<K, V> serialized = new CacheElementSerialized<>( @@ -116,22 +112,18 @@ public class SerializationConversionUtil V deSerializedValue = null; - if ( elementSerializer != null ) + if ( elementSerializer == null ) { + // we could just use the default. + throw new IOException( "Could not de-serialize object. The ElementSerializer is null." ); + } + try { - try - { - deSerializedValue = elementSerializer.deSerialize( serialized.getSerializedValue(), null ); - } - catch ( final ClassNotFoundException | IOException e ) - { - log.error( "Problem de-serializing object.", e ); - throw e; - } + deSerializedValue = elementSerializer.deSerialize( serialized.getSerializedValue(), null ); } - else + catch ( final ClassNotFoundException | IOException e ) { - // we could just use the default. - throw new IOException( "Could not de-serialize object. The ElementSerializer is null." ); + log.error( "Problem de-serializing object.", e ); + throw e; } final ICacheElement<K, V> deSerialized = new CacheElement<>( serialized.getCacheName(), serialized.getKey(), deSerializedValue ); deSerialized.setElementAttributes( serialized.getElementAttributes() ); diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/struct/AbstractLRUMap.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/struct/AbstractLRUMap.java index 53b56b0..c744d7e 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/struct/AbstractLRUMap.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/struct/AbstractLRUMap.java @@ -318,22 +318,18 @@ public abstract class AbstractLRUMap<K, V> try { final LRUElementDescriptor<K, V> last = list.getLast(); - if (last != null) - { - processRemovedLRU(last.getKey(), last.getPayload()); - if (map.remove(last.getKey()) == null) - { - log.warn("update: remove failed for key: {0}", - () -> last.getKey()); - verifyCache(); - } - list.removeLast(); + if (last == null) { + verifyCache(); + throw new Error("update: last is null!"); } - else + processRemovedLRU(last.getKey(), last.getPayload()); + if (map.remove(last.getKey()) == null) { + log.warn("update: remove failed for key: {0}", + () -> last.getKey()); verifyCache(); - throw new Error("update: last is null!"); } + list.removeLast(); } finally { diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/DiskTestObject.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/DiskTestObject.java index ed0fa34..c8a7457 100644 --- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/DiskTestObject.java +++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/DiskTestObject.java @@ -61,7 +61,8 @@ public class DiskTestObject implements Serializable final DiskTestObject o = (DiskTestObject) other; if (id != null) { return id.equals(o.id) && Arrays.equals(imageBytes, o.imageBytes); - } else if (id == null && o.id == null) { + } + if (id == null && o.id == null) { return Arrays.equals(imageBytes, o.imageBytes); } } diff --git a/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs3/jcache/openjpa/OpenJPAJCacheDataCache.java b/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs3/jcache/openjpa/OpenJPAJCacheDataCache.java index 093d444..41959e4 100644 --- a/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs3/jcache/openjpa/OpenJPAJCacheDataCache.java +++ b/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs3/jcache/openjpa/OpenJPAJCacheDataCache.java @@ -54,10 +54,7 @@ public class OpenJPAJCacheDataCache extends AbstractDataCache { return null; } - else - { - result = cache.get(oid); - } + result = cache.get(oid); } else { diff --git a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCache.java b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCache.java index a5cd1b1..e7c3a29 100644 --- a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCache.java +++ b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCache.java @@ -501,7 +501,7 @@ public class JCSCache<K, V> implements Cache<K, V> remove(key); return true; } - else if (v != null) + if (v != null) { // weird but just for stats to be right (org.jsr107.tck.expiry.CacheExpiryTest.removeSpecifiedEntryShouldNotCallExpiryPolicyMethods()) expiryPolicy.getExpiryForAccess(); @@ -596,7 +596,7 @@ public class JCSCache<K, V> implements Cache<K, V> put(key, newValue); return true; } - else if (value != null) + if (value != null) { final Duration expiryForAccess = expiryPolicy.getExpiryForAccess(); if (expiryForAccess != null && (!elt.getElementAttributes().getIsEternal() || !expiryForAccess.isEternal())) @@ -635,7 +635,7 @@ public class JCSCache<K, V> implements Cache<K, V> put(key, value); return true; } - else if (statisticsEnabled) + if (statisticsEnabled) { statistics.increaseMisses(1); } @@ -666,7 +666,7 @@ public class JCSCache<K, V> implements Cache<K, V> put(key, value); return oldValue; } - else if (statisticsEnabled) + if (statisticsEnabled) { statistics.increaseMisses(1); } @@ -739,7 +739,7 @@ public class JCSCache<K, V> implements Cache<K, V> doLoad(k, containsKey(k), now, completionListener != null); continue; } - else if (containsKey(k)) + if (containsKey(k)) { continue; } diff --git a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java index 7df782d..efa5dc4 100644 --- a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java +++ b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java @@ -210,20 +210,16 @@ public class JCSCachingManager implements CacheManager assertNotNull(configuration, "configuration"); final Class<?> keyType = configuration == null ? Object.class : configuration.getKeyType(); final Class<?> valueType = configuration == null ? Object.class : configuration.getValueType(); - if (!caches.containsKey(cacheName)) - { - final Cache<K, V> cache = ClassLoaderAwareCache.wrap(loader, - new JCSCache/*<K, V>*/( - loader, this, cacheName, - new JCSConfiguration/*<K, V>*/(configuration, keyType, valueType), - properties, - ExpiryAwareCache.class.cast(delegate.getCache(cacheName)))); - caches.putIfAbsent(cacheName, cache); - } - else - { + if (caches.containsKey(cacheName)) { throw new javax.cache.CacheException("cache " + cacheName + " already exists"); } + final Cache<K, V> cache = ClassLoaderAwareCache.wrap(loader, + new JCSCache/*<K, V>*/( + loader, this, cacheName, + new JCSConfiguration/*<K, V>*/(configuration, keyType, valueType), + properties, + ExpiryAwareCache.class.cast(delegate.getCache(cacheName)))); + caches.putIfAbsent(cacheName, cache); return (Cache<K, V>) getCache(cacheName, keyType, valueType); }