Skip to content

Commit f5b26b6

Browse files
committed
Types casts fix two FindBugs report of RV_ABSOLUTE_VALUE_OF_RANDOM_INT.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1379436 13f79535-47bb-0310-9956-ffa450edef68
1 parent 982ece6 commit f5b26b6

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ public static String crypt(byte[] original, String salt) {
238238
if (salt == null) {
239239
Random randomGenerator = new Random();
240240
int numSaltChars = SALT_CHARS.length;
241-
salt = "" + SALT_CHARS[Math.abs(randomGenerator.nextInt()) % numSaltChars] +
242-
SALT_CHARS[Math.abs(randomGenerator.nextInt()) % numSaltChars];
241+
// 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];
243244
} else if (!salt.matches("^[" + B64.B64T + "]{2,}$")) {
244245
throw new IllegalArgumentException("Invalid salt value: " + salt);
245246
}

0 commit comments

Comments
 (0)