commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1382485 - /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java
Date Sun, 09 Sep 2012 12:57:11 GMT
Author: sebb
Date: Sun Sep  9 12:57:11 2012
New Revision: 1382485

URL: http://svn.apache.org/viewvc?rev=1382485&view=rev
Log:
Add default case: cannot happen currently, so throw IllegalStateException to trap invalid
code changes

Modified:
    commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java

Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java?rev=1382485&r1=1382484&r2=1382485&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java Sun
Sep  9 12:57:11 2012
@@ -352,6 +352,9 @@ public class Base32 extends BaseNCodec {
                     buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) &
MASK_8BITS);
                     buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
                     break;
+                default:
+                    // modulus can be 0-7, and we excluded 0,1 already
+                    throw new IllegalStateException("Impossible modulus "+context.modulus);
             }
         }
     }
@@ -386,6 +389,8 @@ public class Base32 extends BaseNCodec {
             final byte[] buffer = ensureBufferSize(encodeSize, context);
             final int savedPos = context.pos;
             switch (context.modulus) { // % 5
+                case 0 : // TODO - correct?
+                    break;
                 case 1 : // Only 1 octet; take top 5 bits then remainder
                     buffer[context.pos++] = encodeTable[(int)(context.lbitWorkArea >>
3) & MASK_5BITS]; // 8-1*5 = 3
                     buffer[context.pos++] = encodeTable[(int)(context.lbitWorkArea <<
2) & MASK_5BITS]; // 5-3=2
@@ -426,6 +431,8 @@ public class Base32 extends BaseNCodec {
                     buffer[context.pos++] = encodeTable[(int)(context.lbitWorkArea <<
 3) & MASK_5BITS]; // 5-2 = 3
                     buffer[context.pos++] = PAD;
                     break;
+                default:
+                    throw new IllegalStateException("Impossible modulus "+context.modulus);
             }
             context.currentLinePos += context.pos - savedPos; // keep track of current line
position
             // if currentPos == 0 we are at the start of a line, so don't add CRLF



Mime
View raw message