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

Benedikt Ritter closed VALIDATOR-308.
-------------------------------------

> Logical errors in util.Flags affecting check of multiple flags as well as 
> flag 64
> ---------------------------------------------------------------------------------
>
>                 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
>             Fix For: 1.4.1 Release
>
>         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 was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to