Re: BUG - different writing and reading of Long value
Martin Matula <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.mdr.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Jan,
thanks for finding this bug. Hopefully it is now fixed. Next time please
use issuezilla for reporting bugs and sending patches.
Thanks,
Martin
Jan Kozusznik wrote:
> Hello developers,
> *PROBLEM:*
> There was bug in saving value of type Long. When I set Long attribute
> to 1027634400000 and later I restarted NBMDR this attribute had
> different value. I found bug in IOUtils in method readLong. There was code:
>
> case T_LONG | 0x80: {
> int ch1, ch2, ch3, ch4;
> long v;
>
> ch1 = inputStream.read();
> ch2 = inputStream.read();
> ch3 = inputStream.read();
> ch4 = inputStream.read();
> v = (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + ch1;
> ch1 = inputStream.read();
> ch2 = inputStream.read();
> ch3 = inputStream.read();
> ch4 = inputStream.read();
> return v << 32 + ((ch4 << 24) + (ch3 << 16) + (ch2 << 8)
> + ch1);
>
> but in readLong there was code:
>
> outputStream.write(T_LONG | 0x80);
> outputStream.write((byte)(val & 0xff));
> outputStream.write((byte)((val & 0xff00) >>> 8));
> outputStream.write((byte)((val >>> 16) & 0xff));
> outputStream.write((byte)((val >>> 24) & 0xff));
> outputStream.write((byte)((val >>> 32) & 0xff));
> outputStream.write((byte)((val >>> 40) & 0xff));
> outputStream.write((byte)((val >>> 48) & 0xff));
> outputStream.write((byte)((val >>> 56) & 0xff));
>
> As you can see lower 32-bits were writted as first ones and upper
> 32-bits as second. But reading was reversed.
>
> *SOLUTION:
>
>
> *put in method readLong new code:
> case T_LONG | 0x80: {
> int ch1, ch2, ch3, ch4;
> long v_low,v_high;
> //add by kozusznikj
> ch1 = inputStream.read();
> ch2 = inputStream.read();
> ch3 = inputStream.read();
> ch4 = inputStream.read();
> v_low = (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + ch1;
> ch1 = inputStream.read();
> ch2 = inputStream.read();
> ch3 = inputStream.read();
> ch4 = inputStream.read();
> v_high = ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + ch1);
> return (v_high << 32) + v_low;
>
>
>
> Jan Kozusznik
> Disnet Software,a.s.
>