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 841eef155b003369cd56888101e8188dff2d62a1
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Jul 9 19:32:00 2024 -0400

    Use final
---
 .../yajcache/file/CacheFileContentCorrupted.java   | 10 ++---
 .../commons/jcs/yajcache/file/CacheFileDAO.java    | 46 +++++++++++-----------
 .../jcs/yajcache/file/CacheFileDAOTest.java        | 16 ++++----
 3 files changed, 35 insertions(+), 37 deletions(-)

diff --git 
a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileContentCorrupted.java
 
b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileContentCorrupted.java
index dcbc5092..7fdf8211 100644
--- 
a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileContentCorrupted.java
+++ 
b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileContentCorrupted.java
@@ -33,7 +33,7 @@ public class CacheFileContentCorrupted extends 
CacheFileContent {
 
     private CacheFileContentCorrupted() {}
 
-    @Override void write(@NonNullable RandomAccessFile raf) throws IOException
+    @Override void write(@NonNullable final RandomAccessFile raf) throws 
IOException
     {
     }
 
@@ -41,28 +41,28 @@ public class CacheFileContentCorrupted extends 
CacheFileContent {
         return null;
     }
 
-    @Override public void setContent(byte[] content) {
+    @Override public void setContent(final byte[] content) {
     }
 
     @Override public byte getContentType() {
         return 0;
     }
 
-    @Override public void setContentType(byte contentType) {
+    @Override public void setContentType(final byte contentType) {
     }
 
     @Override public int getContentLength() {
         return 0;
     }
 
-    @Override void setContentLength(int contentLength) {
+    @Override void setContentLength(final int contentLength) {
     }
 
     @Override public int getContentHashCode() {
         return 0;
     }
 
-    @Override void setContentHashCode(int contentHashCode) {
+    @Override void setContentHashCode(final int contentHashCode) {
     }
     @Override public boolean isValid() {
         return false;
diff --git 
a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileDAO.java
 
b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileDAO.java
index 586d4117..f6fa33ff 100644
--- 
a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileDAO.java
+++ 
b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileDAO.java
@@ -37,15 +37,15 @@ import org.apache.commons.logging.LogFactory;
 public enum CacheFileDAO {
     inst;
 
-    private AtomicInteger countWriteIOException = new AtomicInteger();
-    private AtomicInteger countWriteCloseException = new AtomicInteger();
-    private AtomicInteger countReadIOException = new AtomicInteger();
-    private AtomicInteger countReadCloseException = new AtomicInteger();
-    private AtomicInteger countCorruptMinLength = new AtomicInteger();
-    private AtomicInteger countCorruptLength = new AtomicInteger();
-    private AtomicInteger countCorruptInvalid = new AtomicInteger();
+    private final AtomicInteger countWriteIOException = new AtomicInteger();
+    private final AtomicInteger countWriteCloseException = new AtomicInteger();
+    private final AtomicInteger countReadIOException = new AtomicInteger();
+    private final AtomicInteger countReadCloseException = new AtomicInteger();
+    private final AtomicInteger countCorruptMinLength = new AtomicInteger();
+    private final AtomicInteger countCorruptLength = new AtomicInteger();
+    private final AtomicInteger countCorruptInvalid = new AtomicInteger();
 
-    private Log log = LogFactory.getLog(this.getClass());
+    private final Log log = LogFactory.getLog(this.getClass());
 
     /**
      * Writes the specified cache item into the file system.
@@ -53,10 +53,10 @@ public enum CacheFileDAO {
      * @return true if successful; false otherwise.
      */
     public boolean writeCacheItem(
-            @NonNullable String cacheName, @NonNullable CacheFileContentType 
type,
-            @NonNullable String key, @NonNullable byte[] val)
+            @NonNullable final String cacheName, @NonNullable final 
CacheFileContentType type,
+            @NonNullable final String key, @NonNullable final byte[] val)
     {
-        File file = CacheFileUtils.inst.getCacheFile(cacheName, key);
+        final File file = CacheFileUtils.inst.getCacheFile(cacheName, key);
         RandomAccessFile raf = null;
         try {
             file.delete();
@@ -64,14 +64,14 @@ public enum CacheFileDAO {
             raf = new RandomAccessFile(file, "rw");
             CacheFileContent.getInstance(type, val).write(raf);
             return true;
-        } catch (IOException ex) {
+        } catch (final IOException ex) {
             countWriteIOException.incrementAndGet();
             log.error("", ex);
         } finally {
             if (raf != null) {
                 try {
                     raf.close();
-                } catch (Exception ex) {
+                } catch (final Exception ex) {
                     countWriteCloseException.incrementAndGet();
                     log.error("", ex);
                 }
@@ -86,12 +86,13 @@ public enum CacheFileDAO {
      * or null if it doesn't exist;
      * or CacheFileContent.CORRUPTED if file is corrupted.
      */
-    public CacheFileContent readCacheItem(@NonNullable String cacheName, 
@NonNullable String key)
+    public CacheFileContent readCacheItem(@NonNullable final String cacheName, 
@NonNullable final String key)
     {
-        File file = CacheFileUtils.inst.getCacheFile(cacheName, key);
+        final File file = CacheFileUtils.inst.getCacheFile(cacheName, key);
 
-        if (!file.exists())
+        if (!file.exists()) {
             return null;
+        }
         final long fileSize = file.length();
 
         if (fileSize <= CacheFileContent.MIN_FILE_LENGTH) {
@@ -103,7 +104,7 @@ public enum CacheFileDAO {
         RandomAccessFile raf = null;
         try {
             raf = new RandomAccessFile(file, "r");
-            CacheFileContent cfc = CacheFileContent.getInstance(raf);
+            final CacheFileContent cfc = CacheFileContent.getInstance(raf);
 
             if (cfc.isValid()) {
                 final int contentLength = (int)fileSize - 
CacheFileContent.MIN_FILE_LENGTH;
@@ -123,17 +124,14 @@ public enum CacheFileDAO {
                 return CacheFileContent.CORRUPTED;
             }
             return cfc;
-        } catch (IOException ex) {
-            countReadIOException.incrementAndGet();
-            log.warn(ex.getClass().getName(), ex);
-        } catch (org.apache.commons.lang3.SerializationException ex) {
+        } catch (final IOException | 
org.apache.commons.lang3.SerializationException ex) {
             countReadIOException.incrementAndGet();
             log.warn(ex.getClass().getName(), ex);
        } finally {
             if (raf != null) {
                 try {
                     raf.close();
-                } catch (Exception ex) {
+                } catch (final Exception ex) {
                     countReadCloseException.incrementAndGet();
                     log.error("", ex);
                 }
@@ -146,9 +144,9 @@ public enum CacheFileDAO {
      *
      * @return true if successful; false otherwise.
      */
-    public boolean removeCacheItem(@NonNullable String cacheName, @NonNullable 
String key)
+    public boolean removeCacheItem(@NonNullable final String cacheName, 
@NonNullable final String key)
     {
-        File file = CacheFileUtils.inst.getCacheFile(cacheName, key);
+        final File file = CacheFileUtils.inst.getCacheFile(cacheName, key);
         return file.delete();
     }
 
diff --git 
a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/CacheFileDAOTest.java
 
b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/CacheFileDAOTest.java
index 5ca2c4eb..24d93039 100644
--- 
a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/CacheFileDAOTest.java
+++ 
b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/CacheFileDAOTest.java
@@ -35,7 +35,7 @@ import org.apache.commons.logging.LogFactory;
 @CopyRightApache
 @TestOnly
 public class CacheFileDAOTest extends TestCase {
-    private Log log = LogFactory.getLog(this.getClass());
+    private final Log log = LogFactory.getLog(this.getClass());
 
     public void test() {
         log.debug("testing cache directory "
@@ -46,17 +46,17 @@ public class CacheFileDAOTest extends TestCase {
         assertTrue(CacheFileUtils.inst.mkCacheDirs("testCache"));
 
         log.debug("test writeCacheItem");
-        byte[] ba1 = {1, 2, 3, 4};
+        final byte[] ba1 = {1, 2, 3, 4};
         CacheFileDAO.inst.writeCacheItem("testCache",
                 CacheFileContentType.JAVA_SERIALIZATION, "key1", ba1);
-        byte[] ba2 = {'a', 'b', 'c', 'd'};
+        final byte[] ba2 = {'a', 'b', 'c', 'd'};
         CacheFileDAO.inst.writeCacheItem("testCache",
                 CacheFileContentType.XML_ENCODER, "key2", ba2);
 
         log.debug("test readCacheItem");
-        byte[] ba1r = CacheFileDAO.inst.readCacheItem("testCache", 
"key1").getContent();
+        final byte[] ba1r = CacheFileDAO.inst.readCacheItem("testCache", 
"key1").getContent();
         assertTrue(Arrays.equals(ba1, ba1r));
-        byte[] ba2r = (byte[]) CacheFileDAO.inst.readCacheItem("testCache", 
"key2").getContent();
+        final byte[] ba2r = (byte[]) 
CacheFileDAO.inst.readCacheItem("testCache", "key2").getContent();
         assertTrue(Arrays.equals(ba2, ba2r));
 
         log.debug("test removeCacheItem");
@@ -70,13 +70,13 @@ public class CacheFileDAOTest extends TestCase {
 
         log.debug("test readCacheItem missing content");
         CacheFileContent cfc = 
CacheFileDAO.inst.readCacheItem("testCacheCorrupt", "keyx");
-        byte[] ba = cfc == null ? null : cfc.getContent();
+        final byte[] ba = cfc == null ? null : cfc.getContent();
         assertTrue(ba == null);
 
         log.debug("test readCacheItem with corrupted hash code");
-        File file = CacheFileUtils.inst.getCacheFile("testCacheCorrupt", 
"keyy");
+        final File file = CacheFileUtils.inst.getCacheFile("testCacheCorrupt", 
"keyy");
         RandomAccessFile raf = new RandomAccessFile(file, "rw");
-        byte[] ba2 = {1, 2, 3, 4};
+        final byte[] ba2 = {1, 2, 3, 4};
         cfc = 
CacheFileContent.getInstance(CacheFileContentType.JAVA_SERIALIZATION, ba2);
         cfc.setContentHashCode(0);
         cfc.write(raf);

Reply via email to