commons-issues mailing list archives

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

    [ https://issues.apache.org/jira/browse/CODEC-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13446758#comment-13446758
] 

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: https://issues.apache.org/jira/browse/CODEC-150
>             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
> https://github.com/lathspell/commons-codec/commit/ec75321169e624d1a4c44c3ab79d86fbd9e18a01

--
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: http://www.atlassian.com/software/jira

Mime
View raw message