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

Timothy Bish updated AMQ-6431:
------------------------------
    Description: 
I have a problem with "messageid deplicate". Then I found it's a bug(AMQ-5016) 
in activemq5.9.0 , so I download the activemq5.14.0. I run the 
BitArrayBinTest.java:

{code}
 public static void main(String[] args) {
       BitArrayBin toTest = new BitArrayBin(1024);
       long largeNum = Integer.MAX_VALUE*2L +100L;
       toTest.setBit(largeNum, true);
       System.out.println(toTest.getBit(largeNum));   
}
{code}

 I expect the results to be "true",but the result of running the above code is 
"false". 
I debug the code,and I  found a method 'getBin(long index)' in class 
BitArrayBin. Code as follows:

{code}
private int getBin(long index) {
        int answer = 0;
        if (longFirstIndex < 0) {
            longFirstIndex = (int) (index - (index % BitArray.LONG_SIZE));
        } else if (longFirstIndex >= 0) {
            answer = (int)((index - longFirstIndex) / BitArray.LONG_SIZE);
        }
        return answer;
    }
{code}

 I think the problem is in  code ‘longFirstIndex = (int) (index - (index % 
BitArray.LONG_SIZE))‘.  When  index is larger than Integer.MAX_VALUE, 
longFirstIndex will be negative.  I think this line of code should be modified 
to  ‘longFirstIndex = (long) (index - (index % BitArray.LONG_SIZE));’
   


    

  was:
I have a problem with "messageid deplicate". Then I found it's a bug(AMQ-5016) 
in activemq5.9.0 , so I download the activemq5.14.0. I run the 
BitArrayBinTest.java:

 public static void main(String[] args) {
       BitArrayBin toTest = new BitArrayBin(1024);
       long largeNum = Integer.MAX_VALUE*2L +100L;
       toTest.setBit(largeNum, true);
       System.out.println(toTest.getBit(largeNum));   
}

 I expect the results to be "true",but the result of running the above code is 
"false". 
I debug the code,and I  found a method 'getBin(long index)' in class 
BitArrayBin. Code as follows:

private int getBin(long index) {
        int answer = 0;
        if (longFirstIndex < 0) {
            longFirstIndex = (int) (index - (index % BitArray.LONG_SIZE));
        } else if (longFirstIndex >= 0) {
            answer = (int)((index - longFirstIndex) / BitArray.LONG_SIZE);
        }
        return answer;
    }
 I think the problem is in  code ‘longFirstIndex = (int) (index - (index % 
BitArray.LONG_SIZE))‘.  When  index is larger than Integer.MAX_VALUE, 
longFirstIndex will be negative.  I think this line of code should be modified 
to  ‘longFirstIndex = (long) (index - (index % BitArray.LONG_SIZE));’
   


    


> BitArrayBin doesn't work well with index larger than Integer.MAX_VALUE
> ----------------------------------------------------------------------
>
>                 Key: AMQ-6431
>                 URL: https://issues.apache.org/jira/browse/AMQ-6431
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: JMS client
>    Affects Versions: 5.14.0
>            Reporter: 王庆焕
>
> I have a problem with "messageid deplicate". Then I found it's a 
> bug(AMQ-5016) in activemq5.9.0 , so I download the activemq5.14.0. I run the 
> BitArrayBinTest.java:
> {code}
>  public static void main(String[] args) {
>        BitArrayBin toTest = new BitArrayBin(1024);
>        long largeNum = Integer.MAX_VALUE*2L +100L;
>        toTest.setBit(largeNum, true);
>        System.out.println(toTest.getBit(largeNum));   
> }
> {code}
>  I expect the results to be "true",but the result of running the above code 
> is "false". 
> I debug the code,and I  found a method 'getBin(long index)' in class 
> BitArrayBin. Code as follows:
> {code}
> private int getBin(long index) {
>         int answer = 0;
>         if (longFirstIndex < 0) {
>             longFirstIndex = (int) (index - (index % BitArray.LONG_SIZE));
>         } else if (longFirstIndex >= 0) {
>             answer = (int)((index - longFirstIndex) / BitArray.LONG_SIZE);
>         }
>         return answer;
>     }
> {code}
>  I think the problem is in  code ‘longFirstIndex = (int) (index - (index % 
> BitArray.LONG_SIZE))‘.  When  index is larger than Integer.MAX_VALUE, 
> longFirstIndex will be negative.  I think this line of code should be 
> modified to  ‘longFirstIndex = (long) (index - (index % BitArray.LONG_SIZE));’
>    
>     



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to