commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Hammers (JIRA)" <>
Subject [jira] [Commented] (CODEC-150) Remove unnecessary call to Math.abs()
Date Sat, 01 Sep 2012 16:40:07 GMT


Christian Hammers commented on CODEC-150:

The intend was to get a random index i.e. a random number between 0 and numSaltChars-1.

The old code generated a random number between ca. -2^31 and +2^31, then cuts off the sign
and adds modulo numSaltChars to get the intended range. It was actually buggy as abs() does
not work for Integer.MIN_VALUE as findbugs explained to me.

The new code just calls Random.nextInt(numSaltChars) which gives exactly the required range
and looks less ugly.

> Remove unnecessary call to Math.abs()
> -------------------------------------
>                 Key: CODEC-150
>                 URL:
>             Project: Commons Codec
>          Issue Type: Improvement
>    Affects Versions: 1.6
>            Reporter: Christian Hammers
>            Priority: Minor
>         Attachments: commons-codec-chammers-20120901-math-abs.diff
> As spotted by findbugs. Diff attached and online at

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message