Skip to content

Commit 20df4c9

Browse files
committed
Fix SpotBugs [ERROR] Medium:
org.apache.commons.codec.binary.BaseNCodec$AbstractBuilder.setEncodeTable(byte[]) may expose internal representation by storing an externally mutable object into BaseNCodec$AbstractBuilder.encodeTable [org.apache.commons.codec.binary.BaseNCodec$AbstractBuilder] At BaseNCodec.java:[line 131] EI_EXPOSE_REP2
1 parent 45f549c commit 20df4c9

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The <action> type attribute can be add,update,fix,remove.
6363
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix PMD multiple UnnecessaryFullyQualifiedName in org.apache.commons.codec.digest.Blake3.</action>
6464
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix PMD UnnecessaryFullyQualifiedName in org.apache.commons.codec.digest.Md5Crypt.</action>
6565
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix PMD EmptyControlStatement in org.apache.commons.codec.language.Metaphone.</action>
66+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: org.apache.commons.codec.binary.BaseNCodec$AbstractBuilder.setEncodeTable(byte[]) may expose internal representation by storing an externally mutable object into BaseNCodec$AbstractBuilder.encodeTable [org.apache.commons.codec.binary.BaseNCodec$AbstractBuilder] At BaseNCodec.java:[line 131] EI_EXPOSE_REP2.</action>
6667
<!-- ADD -->
6768
<action type="add" dev="ggregory" due-to="Gary Gregory">Add HmacUtils.hmac(Path).</action>
6869
<action type="add" dev="ggregory" due-to="Gary Gregory">Add HmacUtils.hmacHex(Path).</action>

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ private Base64(final int lineLength, final byte[] lineSeparator, final byte padd
667667
if (encodeTable.length != STANDARD_ENCODE_TABLE.length) {
668668
throw new IllegalArgumentException("encodeTable must have exactly 64 entries.");
669669
}
670-
this.isUrlSafe = encodeTable == URL_SAFE_ENCODE_TABLE;
670+
// same array first or equal contents second
671+
this.isUrlSafe = encodeTable == URL_SAFE_ENCODE_TABLE || Arrays.equals(encodeTable, URL_SAFE_ENCODE_TABLE);
671672
if (encodeTable == STANDARD_ENCODE_TABLE || this.isUrlSafe) {
672673
decodeTable = DECODE_TABLE;
673674
// No need of a defensive copy of an internal table.

src/main/java/org/apache/commons/codec/binary/BaseNCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public B setDecodingPolicy(final CodecPolicy decodingPolicy) {
128128
* @return {@code this} instance.
129129
*/
130130
public B setEncodeTable(final byte... encodeTable) {
131-
this.encodeTable = encodeTable != null ? encodeTable : defaultEncodeTable;
131+
this.encodeTable = encodeTable != null ? encodeTable.clone() : defaultEncodeTable;
132132
return asThis();
133133
}
134134

0 commit comments

Comments
 (0)