commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Til Boerner (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (VALIDATOR-308) Logical errors in util.Flags
Date Mon, 30 Jul 2012 21:09:33 GMT

     [ https://issues.apache.org/jira/browse/VALIDATOR-308?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Til Boerner updated VALIDATOR-308:
----------------------------------

    Attachment: flags_test_patch.diff
                flags_impl_patch.diff

Patches for tests and implementation of util.Flags
                
> Logical errors in util.Flags
> ----------------------------
>
>                 Key: VALIDATOR-308
>                 URL: https://issues.apache.org/jira/browse/VALIDATOR-308
>             Project: Commons Validator
>          Issue Type: Bug
>          Components: Framework
>    Affects Versions: 1.4.0 Release
>         Environment: any; flawed logic is independent of environment
>            Reporter: Til Boerner
>            Priority: Minor
>              Labels: flags, patch
>         Attachments: flags_impl_patch.diff, flags_test_patch.diff
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> I just came across Validator.util.Flags while trying to avoid writing my own flag class.
Two errors caught my eye:
> 1) Java uses two's complement representation for its signed primitives. Two important
consequences: the highest order bit signifies a negative number; Long.MAX_VALUE is not the
value that has all bits set. This affects flag.isOn(long) and flag.turnAllOn() .
> 2) If I understand correctly, flag.isOn(long) is supposed to test if flag has ALL bits
set which are also set in the long argument. Comparing against 0 is the wrong way to do this,
even when correcting for the mistake from 1). By comparing against 0, the test merely checks
if the two values have ANY bits in common, which is not what the method's documentation seems
to imply.
> These cases don't seem to get much use, otherwise this would be a serious problem. (And
already be fixed, is my guess.) But still, it is bad enough to completely ruin the day of
anyone who happens to rely on these features, and the poor soul would rightly curse anyone
who allowed them to persist in this wretched state.
> After submitting this, I can hopefully attach the patch I made. Actually there are two
separate patches: one for the test, which illustrates the problems, and a very simple one
for the Flags implementation, which fixes them.
> Cheerio! :)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message