FileInputStream negative skip
Posted
by Peter Štibraný
on Stack Overflow
See other posts from Stack Overflow
or by Peter Štibraný
Published on 2010-03-11T19:21:18Z
Indexed on
2010/03/11
19:24 UTC
Read the original article
Hit count: 375
I'm trying to find more about history of FileInputStream.skip(negative) operation. According to InputStream documentation:
If n is negative, no bytes are skipped.
It seems that implementation of FileInputStream from Sun used to throw IOException instead, which is now also documented in Javadoc:
If n is negative, an IOException is thrown, even though the skip method of the InputStream superclass does nothing in this case.
I just tried that, and found that FileInputStream.skip(-10)
did in fact return -10
! It didn't threw exception, it didn't even return 0, it returned -10. (I've tried with Java 1.5.0_22 from Sun, and Java 1.6.0_18 from Sun). Is this a known bug? Why hasn't it been fixed, or why documentation is kept the way it is? Can someone point me to some discussion about this issue? I can't find anything.
© Stack Overflow or respective owner