commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1725098 - in /commons/proper/jcs/trunk: commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java src/changes/changes.xml
Date Sun, 17 Jan 2016 15:48:08 GMT
Author: tv
Date: Sun Jan 17 15:48:07 2016
New Revision: 1725098

URL: http://svn.apache.org/viewvc?rev=1725098&view=rev
Log:
Fix JCS-158: NullPointerException in IndexedDiskCache.addToRecycleBin(...)

Modified:
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
    commons/proper/jcs/trunk/src/changes/changes.xml

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=1725098&r1=1725097&r2=1725098&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
Sun Jan 17 15:48:07 2016
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
@@ -128,7 +129,7 @@ public class IndexedDiskCache<K, V> exte
     private int startupSize = 0;
 
     /** the number of bytes free on disk. */
-    private long bytesFree = 0;
+    private AtomicLong bytesFree = new AtomicLong(0);
 
     /** mode we are working on (size or count limited **/
     private DiskLimitType diskLimitType = DiskLimitType.COUNT;
@@ -1174,16 +1175,25 @@ public class IndexedDiskCache<K, V> exte
         // reuse the spot
         if (ded != null)
         {
-            this.adjustBytesFree(ded, true);
+            storageLock.readLock().lock();
 
-            if (doRecycle)
+            try
             {
-                recycle.add(ded);
-                if (log.isDebugEnabled())
+                this.adjustBytesFree(ded, true);
+
+                if (doRecycle)
                 {
-                    log.debug(logCacheName + "recycled ded" + ded);
-                }
+                    recycle.add(ded);
+                    if (log.isDebugEnabled())
+                    {
+                        log.debug(logCacheName + "recycled ded" + ded);
+                    }
 
+                }
+            }
+            finally
+            {
+                storageLock.readLock().unlock();
             }
         }
     }
@@ -1459,17 +1469,17 @@ public class IndexedDiskCache<K, V> exte
      *
      * @return The number bytes free on the disk file.
      */
-    protected synchronized long getBytesFree()
+    protected long getBytesFree()
     {
-        return this.bytesFree;
+        return this.bytesFree.get();
     }
 
     /**
      * Resets the number of bytes that are free.
      */
-    private synchronized void resetBytesFree()
+    private void resetBytesFree()
     {
-        this.bytesFree = 0;
+        this.bytesFree.set(0);
     }
 
     /**
@@ -1479,7 +1489,7 @@ public class IndexedDiskCache<K, V> exte
      * @param ded
      * @param add
      */
-    private synchronized void adjustBytesFree(IndexedDiskElementDescriptor ded, boolean add)
+    private void adjustBytesFree(IndexedDiskElementDescriptor ded, boolean add)
     {
         if (ded != null)
         {
@@ -1487,11 +1497,11 @@ public class IndexedDiskCache<K, V> exte
 
             if (add)
             {
-                this.bytesFree += amount;
+                this.bytesFree.addAndGet(amount);
             }
             else
             {
-                this.bytesFree -= amount;
+                this.bytesFree.addAndGet(-amount);
             }
         }
     }
@@ -1604,8 +1614,8 @@ public class IndexedDiskCache<K, V> exte
             log.error(e);
         }
         elems.add(new StatElement<Integer>("Max Key Size", this.maxKeySize));
-        elems.add(new StatElement<Integer>("Hit Count", Integer.valueOf(this.hitCount.get())));
-        elems.add(new StatElement<Long>("Bytes Free", Long.valueOf(this.bytesFree)));
+        elems.add(new StatElement<AtomicInteger>("Hit Count", this.hitCount));
+        elems.add(new StatElement<AtomicLong>("Bytes Free", this.bytesFree));
         elems.add(new StatElement<Integer>("Optimize Operation Count", Integer.valueOf(this.removeCount)));
         elems.add(new StatElement<Integer>("Times Optimized", Integer.valueOf(this.timesOptimized)));
         elems.add(new StatElement<Integer>("Recycle Count", Integer.valueOf(this.recycleCnt)));

Modified: commons/proper/jcs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1725098&r1=1725097&r2=1725098&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/changes/changes.xml (original)
+++ commons/proper/jcs/trunk/src/changes/changes.xml Sun Jan 17 15:48:07 2016
@@ -20,6 +20,9 @@
 	</properties>
 	<body>
         <release version="2.0" date="unreleased" description="JDK 1.6 based major release">
+            <action issue="JCS-158" dev="tv" type="fix" due-to="Wiktor Niesiobedzki">
+                Fix NullPointerException in IndexedDiskCache.addToRecycleBin(...)
+            </action>
             <action dev="tv" type="update">
                 Reduce synchronization
             </action>



Mime
View raw message