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-codec.git

commit 5323ea81060670913c881fa09a8dbb1c7f128585
Author: Gary D. Gregory <[email protected]>
AuthorDate: Sun Feb 9 17:57:15 2025 -0500

    Add Checkstyle FallThrough
---
 src/conf/checkstyle.xml                            |  1 +
 .../org/apache/commons/codec/binary/Base32.java    |  1 +
 .../apache/commons/codec/digest/MurmurHash2.java   | 18 ++++----
 .../apache/commons/codec/digest/MurmurHash3.java   | 53 ++++++++++++----------
 .../apache/commons/codec/digest/PureJavaCrc32.java | 14 ++++--
 .../commons/codec/digest/PureJavaCrc32C.java       | 15 +++---
 6 files changed, 56 insertions(+), 46 deletions(-)

diff --git a/src/conf/checkstyle.xml b/src/conf/checkstyle.xml
index 01a6381a..52465ce8 100644
--- a/src/conf/checkstyle.xml
+++ b/src/conf/checkstyle.xml
@@ -57,6 +57,7 @@ limitations under the License.
     </module>
     <module name="EqualsHashCode" />
     <module name="ExplicitInitialization" />
+    <module name="FallThrough" />
     <module name="FinalLocalVariable" />
     <module name="IllegalImport" />
     <module name="ImportOrder">
diff --git a/src/main/java/org/apache/commons/codec/binary/Base32.java 
b/src/main/java/org/apache/commons/codec/binary/Base32.java
index 81951aca..258c53b8 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base32.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base32.java
@@ -482,6 +482,7 @@ public class Base32 extends BaseNCodec {
 //              case 0 : // impossible, as excluded above
             case 1: // 5 bits - either ignore entirely, or raise an exception
                 validateTrailingCharacters();
+                // falls-through
             case 2: // 10 bits, drop 2 and output one byte
                 validateCharacter(MASK_2BITS, context);
                 buffer[context.pos++] = (byte) (context.lbitWorkArea >> 2 & 
MASK_8BITS);
diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java 
b/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java
index 1132a166..4ae281ec 100644
--- a/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java
+++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java
@@ -119,10 +119,8 @@ public final class MurmurHash2 {
     public static int hash32(final byte[] data, final int length, final int 
seed) {
         // Initialize the hash to a random value
         int h = seed ^ length;
-
         // Mix 4 bytes at a time into the hash
         final int nblocks = length >> 2;
-
         // body
         for (int i = 0; i < nblocks; i++) {
             final int index = i << 2;
@@ -133,25 +131,24 @@ public final class MurmurHash2 {
             h *= M32;
             h ^= k;
         }
-
         // Handle the last few bytes of the input array
         final int index = nblocks << 2;
         switch (length - index) {
         case 3:
             h ^= (data[index + 2] & 0xff) << 16;
+            // falls-through
         case 2:
             h ^= (data[index + 1] & 0xff) << 8;
+            // falls-through
         case 1:
             h ^= data[index] & 0xff;
             h *= M32;
         }
-
         // Do a few final mixes of the hash to ensure the last few
         // bytes are well-incorporated.
         h ^= h >>> 13;
         h *= M32;
         h ^= h >>> 15;
-
         return h;
     }
 
@@ -227,9 +224,7 @@ public final class MurmurHash2 {
      */
     public static long hash64(final byte[] data, final int length, final int 
seed) {
         long h = seed & 0xffffffffL ^ length * M64;
-
         final int nblocks = length >> 3;
-
         // body
         for (int i = 0; i < nblocks; i++) {
             final int index = i << 3;
@@ -242,30 +237,33 @@ public final class MurmurHash2 {
             h ^= k;
             h *= M64;
         }
-
         final int index = nblocks << 3;
         switch (length - index) {
         case 7:
             h ^= ((long) data[index + 6] & 0xff) << 48;
+            // falls-through
         case 6:
             h ^= ((long) data[index + 5] & 0xff) << 40;
+            // falls-through
         case 5:
             h ^= ((long) data[index + 4] & 0xff) << 32;
+            // falls-through
         case 4:
             h ^= ((long) data[index + 3] & 0xff) << 24;
+            // falls-through
         case 3:
             h ^= ((long) data[index + 2] & 0xff) << 16;
+            // falls-through
         case 2:
             h ^= ((long) data[index + 1] & 0xff) << 8;
+            // falls-through
         case 1:
             h ^= (long) data[index] & 0xff;
             h *= M64;
         }
-
         h ^= h >>> R64;
         h *= M64;
         h ^= h >>> R64;
-
         return h;
     }
 
diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java 
b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
index 3d2a6576..658a0148 100644
--- a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
+++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
@@ -93,18 +93,17 @@ public final class MurmurHash3 {
         @Deprecated
         int finalise(final int hash, final int unprocessedLength, final byte[] 
unprocessed, final int totalLen) {
             int result = hash;
-            // ************
             // Note: This fails to apply masking using 0xff to the 3 remaining 
bytes.
-            // ************
             int k1 = 0;
             switch (unprocessedLength) {
             case 3:
                 k1 ^= unprocessed[2] << 16;
+                // falls-through
             case 2:
                 k1 ^= unprocessed[1] << 8;
+                // falls-through
             case 1:
                 k1 ^= unprocessed[0];
-
                 // mix functions
                 k1 *= C1_32;
                 k1 = Integer.rotateLeft(k1, R1_32);
@@ -274,18 +273,18 @@ public final class MurmurHash3 {
             switch (unprocessedLength) {
             case 3:
                 k1 ^= (unprocessed[2] & 0xff) << 16;
+                // falls-through
             case 2:
                 k1 ^= (unprocessed[1] & 0xff) << 8;
+                // falls-through
             case 1:
                 k1 ^= unprocessed[0] & 0xff;
-
                 // mix functions
                 k1 *= C1_32;
                 k1 = Integer.rotateLeft(k1, R1_32);
                 k1 *= C2_32;
                 result ^= k1;
             }
-
             // finalization
             result ^= totalLen;
             return fmix32(result);
@@ -555,7 +554,6 @@ public final class MurmurHash3 {
             h2 += h1;
             h2 = h2 * M + N2;
         }
-
         // tail
         long k1 = 0;
         long k2 = 0;
@@ -563,37 +561,50 @@ public final class MurmurHash3 {
         switch (offset + length - index) {
         case 15:
             k2 ^= ((long) data[index + 14] & 0xff) << 48;
+            // falls-through
         case 14:
             k2 ^= ((long) data[index + 13] & 0xff) << 40;
+            // falls-through
         case 13:
             k2 ^= ((long) data[index + 12] & 0xff) << 32;
+            // falls-through
         case 12:
             k2 ^= ((long) data[index + 11] & 0xff) << 24;
+            // falls-through
         case 11:
             k2 ^= ((long) data[index + 10] & 0xff) << 16;
+            // falls-through
         case 10:
             k2 ^= ((long) data[index + 9] & 0xff) << 8;
+            // falls-through
         case 9:
             k2 ^= data[index + 8] & 0xff;
             k2 *= C2;
             k2 = Long.rotateLeft(k2, R3);
             k2 *= C1;
             h2 ^= k2;
-
+            // falls-through
         case 8:
             k1 ^= ((long) data[index + 7] & 0xff) << 56;
+            // falls-through
         case 7:
             k1 ^= ((long) data[index + 6] & 0xff) << 48;
+            // falls-through
         case 6:
             k1 ^= ((long) data[index + 5] & 0xff) << 40;
+            // falls-through
         case 5:
             k1 ^= ((long) data[index + 4] & 0xff) << 32;
+            // falls-through
         case 4:
             k1 ^= ((long) data[index + 3] & 0xff) << 24;
+            // falls-through
         case 3:
             k1 ^= ((long) data[index + 2] & 0xff) << 16;
+            // falls-through
         case 2:
             k1 ^= ((long) data[index + 1] & 0xff) << 8;
+            // falls-through
         case 1:
             k1 ^= data[index] & 0xff;
             k1 *= C1;
@@ -601,7 +612,6 @@ public final class MurmurHash3 {
             k1 *= C2;
             h1 ^= k1;
         }
-
         // finalization
         h1 ^= length;
         h2 ^= length;
@@ -713,35 +723,31 @@ public final class MurmurHash3 {
     public static int hash32(final byte[] data, final int offset, final int 
length, final int seed) {
         int hash = seed;
         final int nblocks = length >> 2;
-
         // body
         for (int i = 0; i < nblocks; i++) {
             final int index = offset + (i << 2);
             final int k = getLittleEndianInt(data, index);
             hash = mix32(k, hash);
         }
-
         // tail
-        // ************
         // Note: This fails to apply masking using 0xff to the 3 remaining 
bytes.
-        // ************
         final int index = offset + (nblocks << 2);
         int k1 = 0;
         switch (offset + length - index) {
         case 3:
             k1 ^= data[index + 2] << 16;
+            // falls-through
         case 2:
             k1 ^= data[index + 1] << 8;
+            // falls-through
         case 1:
             k1 ^= data[index];
-
             // mix functions
             k1 *= C1_32;
             k1 = Integer.rotateLeft(k1, R1_32);
             k1 *= C2_32;
             hash ^= k1;
         }
-
         hash ^= length;
         return fmix32(hash);
     }
@@ -913,32 +919,31 @@ public final class MurmurHash3 {
     public static int hash32x86(final byte[] data, final int offset, final int 
length, final int seed) {
         int hash = seed;
         final int nblocks = length >> 2;
-
         // body
         for (int i = 0; i < nblocks; i++) {
             final int index = offset + (i << 2);
             final int k = getLittleEndianInt(data, index);
             hash = mix32(k, hash);
         }
-
         // tail
         final int index = offset + (nblocks << 2);
         int k1 = 0;
         switch (offset + length - index) {
         case 3:
             k1 ^= (data[index + 2] & 0xff) << 16;
+            // falls-through
         case 2:
+            // falls-through
             k1 ^= (data[index + 1] & 0xff) << 8;
+            // falls-through
         case 1:
             k1 ^= data[index] & 0xff;
-
             // mix functions
             k1 *= C1_32;
             k1 = Integer.rotateLeft(k1, R1_32);
             k1 *= C2_32;
             hash ^= k1;
         }
-
         hash ^= length;
         return fmix32(hash);
     }
@@ -1038,17 +1043,13 @@ public final class MurmurHash3 {
      */
     @Deprecated
     public static long hash64(final byte[] data, final int offset, final int 
length, final int seed) {
-        //
         // Note: This fails to apply masking using 0xffffffffL to the seed.
-        //
         long hash = seed;
         final int nblocks = length >> 3;
-
         // body
         for (int i = 0; i < nblocks; i++) {
             final int index = offset + (i << 3);
             long k = getLittleEndianLong(data, index);
-
             // mix functions
             k *= C1;
             k = Long.rotateLeft(k, R1);
@@ -1056,23 +1057,28 @@ public final class MurmurHash3 {
             hash ^= k;
             hash = Long.rotateLeft(hash, R2) * M + N1;
         }
-
         // tail
         long k1 = 0;
         final int index = offset + (nblocks << 3);
         switch (offset + length - index) {
         case 7:
             k1 ^= ((long) data[index + 6] & 0xff) << 48;
+            // falls-through
         case 6:
             k1 ^= ((long) data[index + 5] & 0xff) << 40;
+            // falls-through
         case 5:
             k1 ^= ((long) data[index + 4] & 0xff) << 32;
+            // falls-through
         case 4:
             k1 ^= ((long) data[index + 3] & 0xff) << 24;
+            // falls-through
         case 3:
             k1 ^= ((long) data[index + 2] & 0xff) << 16;
+            // falls-through
         case 2:
             k1 ^= ((long) data[index + 1] & 0xff) << 8;
+            // falls-through
         case 1:
             k1 ^= (long) data[index] & 0xff;
             k1 *= C1;
@@ -1080,7 +1086,6 @@ public final class MurmurHash3 {
             k1 *= C2;
             hash ^= k1;
         }
-
         // finalization
         hash ^= length;
         return fmix64(hash);
diff --git a/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32.java 
b/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32.java
index 0497c138..33bebfeb 100644
--- a/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32.java
+++ b/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32.java
@@ -600,7 +600,6 @@ public class PureJavaCrc32 implements Checksum {
     @Override
     public void update(final byte[] b, final int offset, final int len) {
       int localCrc = crc;
-
       final int remainder = len & 0x7;
       int i = offset;
       for (final int end = offset + len - remainder; i < end; i += 8) {
@@ -613,27 +612,32 @@ public class PureJavaCrc32 implements Checksum {
                    T[(b[i + 4] << 24 >>> 24) + 0x300] ^ T[(b[i + 5] << 24 >>> 
24) + 0x200] ^
                    T[(b[i + 6] << 24 >>> 24) + 0x100] ^ T[b[i + 7] << 24 >>> 
24];
       }
-
-      /* loop unroll - duff's device style */
+      // loop unroll - duff's device style
       switch (remainder) {
       case 7:
           localCrc = localCrc >>> 8 ^ T[(localCrc ^ b[i++]) << 24 >>> 24];
+          // falls-through
       case 6:
           localCrc = localCrc >>> 8 ^ T[(localCrc ^ b[i++]) << 24 >>> 24];
+          // falls-through
       case 5:
           localCrc = localCrc >>> 8 ^ T[(localCrc ^ b[i++]) << 24 >>> 24];
+          // falls-through
       case 4:
           localCrc = localCrc >>> 8 ^ T[(localCrc ^ b[i++]) << 24 >>> 24];
+          // falls-through
       case 3:
           localCrc = localCrc >>> 8 ^ T[(localCrc ^ b[i++]) << 24 >>> 24];
+          // falls-through
       case 2:
           localCrc = localCrc >>> 8 ^ T[(localCrc ^ b[i++]) << 24 >>> 24];
+          // falls-through
       case 1:
           localCrc = localCrc >>> 8 ^ T[(localCrc ^ b[i++]) << 24 >>> 24];
+          // falls-through
       default:
-          /* nothing */
+          // nothing
       }
-
       // Publish crc out to object
       crc = localCrc;
     }
diff --git a/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32C.java 
b/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32C.java
index acf0fd15..d3e16040 100644
--- a/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32C.java
+++ b/src/main/java/org/apache/commons/codec/digest/PureJavaCrc32C.java
@@ -598,45 +598,46 @@ public class PureJavaCrc32C implements Checksum {
     @Override
     public void update(final byte[] b, int off, int len) {
         int localCrc = crc;
-
         while (len > 7) {
             final int c0 = (b[off + 0] ^ localCrc) & 0xff;
             final int c1 = (b[off + 1] ^ (localCrc >>>= 8)) & 0xff;
             final int c2 = (b[off + 2] ^ (localCrc >>>= 8)) & 0xff;
             final int c3 = (b[off + 3] ^ (localCrc >>>= 8)) & 0xff;
             localCrc = T[T8_7_START + c0] ^ T[T8_6_START + c1] ^ T[T8_5_START 
+ c2] ^ T[T8_4_START + c3];
-
             final int c4 = b[off + 4] & 0xff;
             final int c5 = b[off + 5] & 0xff;
             final int c6 = b[off + 6] & 0xff;
             final int c7 = b[off + 7] & 0xff;
-
             localCrc ^= T[T8_3_START + c4] ^ T[T8_2_START + c5] ^ T[T8_1_START 
+ c6] ^ T[T8_0_START + c7];
-
             off += 8;
             len -= 8;
         }
-
-        /* loop unroll - duff's device style */
+        // loop unroll - duff's device style
         switch (len) {
         case 7:
             localCrc = localCrc >>> 8 ^ T[T8_0_START + ((localCrc ^ b[off++]) 
& 0xff)];
+            // falls-through
         case 6:
             localCrc = localCrc >>> 8 ^ T[T8_0_START + ((localCrc ^ b[off++]) 
& 0xff)];
+            // falls-through
         case 5:
             localCrc = localCrc >>> 8 ^ T[T8_0_START + ((localCrc ^ b[off++]) 
& 0xff)];
+            // falls-through
         case 4:
             localCrc = localCrc >>> 8 ^ T[T8_0_START + ((localCrc ^ b[off++]) 
& 0xff)];
+            // falls-through
         case 3:
             localCrc = localCrc >>> 8 ^ T[T8_0_START + ((localCrc ^ b[off++]) 
& 0xff)];
+            // falls-through
         case 2:
             localCrc = localCrc >>> 8 ^ T[T8_0_START + ((localCrc ^ b[off++]) 
& 0xff)];
+            // falls-through
         case 1:
             localCrc = localCrc >>> 8 ^ T[T8_0_START + ((localCrc ^ b[off++]) 
& 0xff)];
+            // falls-through
         default:
             break; // satisfy Findbugs
         }
-
         // Publish crc out to object
         crc = localCrc;
     }

Reply via email to