[XADISK-128] NativeXAFileInputStream skip method throws an unexpected IllegalArgumentException with message "New position cannot be negative or more than file size" Created: 23/Jan/13 Updated: 27/Aug/13 Resolved: 09/Aug/13
|Reporter:||Marco Quaranta||Assignee:||Nitin Verma|
|Remaining Estimate:||Not Specified|
|Time Spent:||Not Specified|
|Original Estimate:||Not Specified|
|Tags:||NativeXAFileInputStream, inputstream, skip|
Calling skip method on XAFileInputStream generate IllegalArgumentException due to wrongly calculated readPositionAfterSkip.
(NativeXAFileInputStream.java line 175)
Using a position equals to 0 and skipping 200 bytes with a generic file larger than 200 bytes this expression return a negative value and than, the subsequential calling to "position(readPositionAfterSkip)" method, will throws IllegalArgumentException.
Why don't simply use this?
|Comment by Nitin Verma [ 07/Feb/13 ]|
I could reproduce the issue if I try to skip some bytes just after opening the input stream, before any call to read etc. (so, a workaround is to read one byte anyway for the first time, xafis.read())
The logic is failing because byteBuffer is not yet filled. There needs to be a check on flag filledAtleastOnce.
We need to take into account the value of byteBuffer.remaining(); the "position" is not the position of the next byte in the file (to be returned to the user), it is an internal variable which is used to track from where in the file the buffer is to be filled next.
|Comment by Nitin Verma [ 09/Aug/13 ]|
Checked-in the changes to trunk.