[ 
https://issues.apache.org/jira/browse/DERBY-2686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12498624
 ] 

Kristian Waagan commented on DERBY-2686:
----------------------------------------

FYI, from this years JavaOne, session TS-2707 - "Java Puzzlers Episode VI: The 
Phantom-Reference Menace/Attack of the Clone/Revenge of the Shift" by Joshua 
Bloch, Google, Inc.; William Pugh, Univ. of Maryland, pdf page 35 and 36:

"static void skipFully(InputStream in, long nBytes)
        throws IOException {
    long remaining = nBytes;
    while (remaining != 0) {
        long skipped = in.skip(remaining);
        if (skipped == 0)
            throw new EOFException();
        remaining -= skipped;
    }
}"

And the following statements:
"Moral
• The skip method is hard to use and error prone
• Use your skipFully instead of skip
• There is an RFE to add it to InputStream
• More generally, if an API is broken, wrap it
• For API designers
  • Don't violate the principle of least astonishment
  • Make it easy to do simple things"

Again, this does not necessarily justify a specific solution/implementation, it 
is just another data point.

> The skip method for some InputStreams and Readers return invalid values
> -----------------------------------------------------------------------
>
>                 Key: DERBY-2686
>                 URL: https://issues.apache.org/jira/browse/DERBY-2686
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC, Store
>    Affects Versions: 10.3.0.0
>            Reporter: Kristian Waagan
>         Assigned To: Kristian Waagan
>         Attachments: derby-2686-1a.diff, derby-2686-1a.stat
>
>
> The Java API docs for InputStream.skip and Reader.skip seem to indicate that 
> returning a negative value is breaking the contract.
> The contract for Reader.skip is the more clear one, while I have taken the 
> assumption that all Derby InputStreams will return 0 only when EOF has been 
> reached or 0 is passed in as the amount of bytes to skip.
> Bad checking in a skip method also caused Derby to enter an infinite loop in 
> a skip method.
> It should also be noted that skipping bytes/characters should be done in a 
> loop, as skip  is free to skip a smaller amount of bytes than requested. This 
> is true even if EOF is not reached.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to