Skip to content

Commit 6d151e7

Browse files
committed
[CODEC-150] Remove unnecessary call to Math.abs().
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1379806 13f79535-47bb-0310-9956-ffa450edef68
1 parent 98a56ae commit 6d151e7

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ The <action> type attribute can be add,update,fix,remove.
5151
</release>
5252
-->
5353
<release version="1.7" date="TBD" description="Feature and fix release.">
54+
<action issue="CODEC-150" dev="ggregory" type="add" due-to="lathspell">
55+
Remove unnecessary call to Math.abs().
56+
</action>
5457
<action issue="CODEC-151" dev="ggregory" type="add" due-to="lathspell">
5558
Remove unnecessary attempt to fill up the salt variable in UnixCrypt.
5659
</action>

src/main/java/org/apache/commons/codec/digest/UnixCrypt.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public static String crypt(byte[] original, String salt) {
239239
Random randomGenerator = new Random();
240240
int numSaltChars = SALT_CHARS.length;
241241
// Types casts fix two FindBugs report of RV_ABSOLUTE_VALUE_OF_RANDOM_INT.
242-
salt = "" + SALT_CHARS[(int)Math.abs((long)randomGenerator.nextInt()) % numSaltChars] +
243-
SALT_CHARS[(int)Math.abs((long)randomGenerator.nextInt()) % numSaltChars];
242+
salt = "" + SALT_CHARS[randomGenerator.nextInt(numSaltChars)] +
243+
SALT_CHARS[randomGenerator.nextInt(numSaltChars)];
244244
} else if (!salt.matches("^[" + B64.B64T + "]{2,}$")) {
245245
throw new IllegalArgumentException("Invalid salt value: " + salt);
246246
}

0 commit comments

Comments
 (0)