Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Ridiculous readInt() bug? Read-head not advancing far enough?

Reply
Thread Tools

Ridiculous readInt() bug? Read-head not advancing far enough?

 
 
nobrow@eircom.net
Guest
Posts: n/a
 
      04-13-2005
This one is just fantastic! I have a large binary file being processed
in Java. After insertion of much debugging code, and with a hex editor
I have discovered the following behaviour.

At some point the DataInputStream (dis) which I am using to read the
file hits the following sequence of bytes;

.... 05 00 00 00 00 00 03 07 C0 08 05 24 18 4D 11 E0 A8 ...

The following sequence of methods are executed;

dis.read() ... gives 5 (0x5) ... fine
dis.readLong() ... gives 198592 (0x00000000000307C0) ... fine
dis.readInt() ... gives 134554648 (0x0805241 ... fine
dis.readInt() ... gives 407704032 (0x184D11E0) ... WTF!?

Notice anything about that last one? ... The last byte read by the
preceeding readInt() is being read as the first byte by this
readInt()!!!!!

The really annoying thing is that its intermittent. Happens every time
today. Worked fine yesterday. Happened every time the day before. There
is nothing unusal about my system. No background processes that could
be getting involved. No changes in it from day to day.

I know posting code would be a good move but the program is quite
involved and difficult to chop down into a minimal example. Suffice it
to say that there is nothing complicated about the offending portion of
the code. The DataInputStream is not being shared across threads or
anything, and those methods are executed in succession, with nothing
else happening in between.

Am running on Linux.

$ java -version
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)

Seriously! Whats that about? Anyone ever seen anything like this before?

 
Reply With Quote
 
 
 
 
El
Guest
Posts: n/a
 
      04-13-2005
Also, on some occassions, an EOFException is thrown, despite the fact
that the DataInputStream is nowhere near the end of the file.

 
Reply With Quote
 
 
 
 
Daniel Dyer
Guest
Posts: n/a
 
      04-13-2005
On Wed, 13 Apr 2005 12:21:12 +0100, <> wrote:

> This one is just fantastic! I have a large binary file being processed
> in Java. After insertion of much debugging code, and with a hex editor
> I have discovered the following behaviour.
>
> At some point the DataInputStream (dis) which I am using to read the
> file hits the following sequence of bytes;
>
> ... 05 00 00 00 00 00 03 07 C0 08 05 24 18 4D 11 E0 A8 ...


Where is the DataInputStream getting this data from? Can you be sure the
bug is in the DataInputStream and not somewhere else? Have you wrapped
the DataInputStream around some other input stream (is the data coming
from a file or a socket)? If the bug is intermittent are you certain that
the above sequence of bytes is exactly what is being fed to the
DataInputStream every time?

Dan.

--
Daniel Dyer
http://www.footballpredictions.net
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      04-13-2005
wrote:

> The really annoying thing is that its intermittent. Happens every time
> today. Worked fine yesterday. Happened every time the day before. There
> is nothing unusal about my system. No background processes that could
> be getting involved. No changes in it from day to day.


I think there must be something very strange about the stream you are reading
from. The source to DataInputStream.readInt() is straightforward and could not
possibly cause the results you are seeing (at least the 1.4.2 for Windows
version is, I assume the Linux version is identical).

Unless someone else recognises the symptoms, I think you'll have to give more
detail about how you are creating the DataInputStream.

Incidentally, can you reproduce the effect on a different Linux box (ideally
one
that does not have an identical installation) ?

-- chris



 
Reply With Quote
 
bugbear
Guest
Posts: n/a
 
      04-13-2005
wrote:
> This one is just fantastic! I have a large binary file being processed
> in Java. After insertion of much debugging code, and with a hex editor
> I have discovered the following behaviour.
>
> At some point the DataInputStream (dis) which I am using to read the
> file hits the following sequence of bytes;
>
> ... 05 00 00 00 00 00 03 07 C0 08 05 24 18 4D 11 E0 A8 ...
>
> The following sequence of methods are executed;
>
> dis.read() ... gives 5 (0x5) ... fine
> dis.readLong() ... gives 198592 (0x00000000000307C0) ... fine
> dis.readInt() ... gives 134554648 (0x0805241 ... fine
> dis.readInt() ... gives 407704032 (0x184D11E0) ... WTF!?
>
> Notice anything about that last one? ... The last byte read by the
> preceeding readInt() is being read as the first byte by this
> readInt()!!!!!
>
> The really annoying thing is that its intermittent. Happens every time
> today. Worked fine yesterday. Happened every time the day before. There
> is nothing unusal about my system. No background processes that could
> be getting involved. No changes in it from day to day.


I would recommend interposing a BufferredInputStream between
your DataInputStream and your actual InputStream, and
messing around with the BufferSize to see what happens.
I suspect this wil "stir the pot".

This sounds (horribly) like a buffer boundary problem
somewhere in your layers of InputStream-nes

BugBear
 
Reply With Quote
 
Alex Buell
Guest
Posts: n/a
 
      04-13-2005
On Wed, 13 Apr 2005 14:15:13 +0100, bugbear
<bugbear@trim_papermule.co.uk_trim> wrote:

> wrote:
>> This one is just fantastic! I have a large binary file being processed
>> in Java. After insertion of much debugging code, and with a hex editor
>> I have discovered the following behaviour.
>>
>> At some point the DataInputStream (dis) which I am using to read the
>> file hits the following sequence of bytes;
>>
>> ... 05 00 00 00 00 00 03 07 C0 08 05 24 18 4D 11 E0 A8 ...
>>
>> The following sequence of methods are executed;
>>
>> dis.read() ... gives 5 (0x5) ... fine
>> dis.readLong() ... gives 198592 (0x00000000000307C0) ... fine
>> dis.readInt() ... gives 134554648 (0x0805241 ... fine
>> dis.readInt() ... gives 407704032 (0x184D11E0) ... WTF!?
>>
>> Notice anything about that last one? ... The last byte read by the
>> preceeding readInt() is being read as the first byte by this
>> readInt()!!!!!
>>
>> The really annoying thing is that its intermittent. Happens every time
>> today. Worked fine yesterday. Happened every time the day before. There
>> is nothing unusal about my system. No background processes that could
>> be getting involved. No changes in it from day to day.

>
>I would recommend interposing a BufferredInputStream between
>your DataInputStream and your actual InputStream, and
>messing around with the BufferSize to see what happens.
>I suspect this wil "stir the pot".
>
>This sounds (horribly) like a buffer boundary problem
>somewhere in your layers of InputStream-nes


Change to BufferedReader instead. Isn't DataInputStream old hat
anyway?

Cheers,
Alex.
--
http://www.munted.org.uk
 
Reply With Quote
 
El
Guest
Posts: n/a
 
      04-13-2005
The DataInputStream is wrapping a FileInputStream.

The nature of the app means that the file varies considerably from
execution to execution. My OP was just one example, but the same thing
happens (with different numbers) each execution.

 
Reply With Quote
 
El
Guest
Posts: n/a
 
      04-13-2005
There really is nothing special about how the stream is created. A
FileInputStream is created and then turned to a DataInputStream.

It is difficult to test on other systems as the project is a cumbersome
in terms of the other bits and pieces that have to be configured in
order to run it so Im pretty much stuck where I am.

 
Reply With Quote
 
El
Guest
Posts: n/a
 
      04-13-2005
I threw a BufferredInputStream into the mix and it worked. I should add
that its only worked once ... the program is slow so itll take a while
to gain confidence in this result.

Thats just bad. You understand what the problem actually is?

Thanks for the suggestion.

 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      04-13-2005
Alex Buell wrote:

> On Wed, 13 Apr 2005 14:15:13 +0100, bugbear
> <bugbear@trim_papermule.co.uk_trim> wrote:
>
>> wrote:
>>> This one is just fantastic! I have a large binary file being processed
>>> in Java. After insertion of much debugging code, and with a hex editor
>>> I have discovered the following behaviour.
>>>
>>> At some point the DataInputStream (dis) which I am using to read the
>>> file hits the following sequence of bytes;
>>>
>>> ... 05 00 00 00 00 00 03 07 C0 08 05 24 18 4D 11 E0 A8 ...
>>>
>>> The following sequence of methods are executed;
>>>
>>> dis.read() ... gives 5 (0x5) ... fine
>>> dis.readLong() ... gives 198592 (0x00000000000307C0) ... fine
>>> dis.readInt() ... gives 134554648 (0x0805241 ... fine
>>> dis.readInt() ... gives 407704032 (0x184D11E0) ... WTF!?
>>>
>>> Notice anything about that last one? ... The last byte read by the
>>> preceeding readInt() is being read as the first byte by this
>>> readInt()!!!!!
>>>
>>> The really annoying thing is that its intermittent. Happens every time
>>> today. Worked fine yesterday. Happened every time the day before. There
>>> is nothing unusal about my system. No background processes that could
>>> be getting involved. No changes in it from day to day.

>>
>>I would recommend interposing a BufferredInputStream between
>>your DataInputStream and your actual InputStream, and
>>messing around with the BufferSize to see what happens.
>>I suspect this wil "stir the pot".
>>
>>This sounds (horribly) like a buffer boundary problem
>>somewhere in your layers of InputStream-nes

>
> Change to BufferedReader instead. Isn't DataInputStream old hat
> anyway?
>
> Cheers,
> Alex.


No, he certainly doesn't want to use any kind of io.Reader. They are for
reading character streams, which would be no use for binary data.

To the OP, could this be a problem with the underlying filesystem? What
happens if you strip out everything apart from the FileInputStream and
DataInputStream to read the data?

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail :
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advancing past the last element of an array Johannes Schaub (litb) C Programming 10 01-13-2010 08:49 AM
ToolTipText pop up far far away from mouse pointer RC Java 2 01-08-2008 12:54 AM
Taking table-less CSS design far too far Andy Dingley HTML 45 06-11-2006 07:14 PM
PC date/time randomly advancing notme Computer Support 1 02-11-2005 08:35 PM
advancing with the asp:datagrid Tim Smith ASP .Net 1 11-25-2003 07:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57