You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dmitry Katsubo (JIRA)" <ji...@apache.org> on 2012/11/06 17:30:12 UTC

[jira] [Created] (IO-356) CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size

Dmitry Katsubo created IO-356:
---------------------------------

             Summary: CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size
                 Key: IO-356
                 URL: https://issues.apache.org/jira/browse/IO-356
             Project: Commons IO
          Issue Type: Bug
          Components: Streams/Writers
    Affects Versions: 2.4
            Reporter: Dmitry Katsubo
         Attachments: CharSequenceInputStreamTest.java

The size effect happens when buffer size of input stream is not dividable by requested data size. The bug is hidden in {{CharSequenceInputStream#reset()}} method which should also call (I think) {{bbuf.limit(0)}} otherwise next call to {{CharSequenceInputStream#read()}} will return the remaining tail which {{bbuf}} has accumulated.

In the attached test case the test fails, if {{dataSize = 13}} (not dividable by 10) and runs OK if {{dataSize = 20}} (dividable by 10).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (IO-356) CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size

Posted by "Dmitry Katsubo (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-356?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dmitry Katsubo updated IO-356:
------------------------------

    Attachment: CharSequenceInputStreamTest.java
    
> CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: IO-356
>                 URL: https://issues.apache.org/jira/browse/IO-356
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.4
>            Reporter: Dmitry Katsubo
>         Attachments: CharSequenceInputStreamTest.java
>
>
> The size effect happens when buffer size of input stream is not dividable by requested data size. The bug is hidden in {{CharSequenceInputStream#reset()}} method which should also call (I think) {{bbuf.limit(0)}} otherwise next call to {{CharSequenceInputStream#read()}} will return the remaining tail which {{bbuf}} has accumulated.
> In the attached test case the test fails, if {{dataSize = 13}} (not dividable by 10) and runs OK if {{dataSize = 20}} (dividable by 10).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (IO-356) CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13491621#comment-13491621 ] 

Sebb commented on IO-356:
-------------------------

Thanks for the report; added the test case:

URL: http://svn.apache.org/viewvc?rev=1406222&view=rev
Log:
IO-356 CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size
Add test case showing the issue

Modified:
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java

If the code "bbuf.limit(0);" is added to the reset() method the tests run OK.

However I'm not 100% sure that's the full solution; perhaps others can comment?
                
> CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: IO-356
>                 URL: https://issues.apache.org/jira/browse/IO-356
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.4
>            Reporter: Dmitry Katsubo
>         Attachments: CharSequenceInputStreamTest.java
>
>
> The size effect happens when buffer size of input stream is not dividable by requested data size. The bug is hidden in {{CharSequenceInputStream#reset()}} method which should also call (I think) {{bbuf.limit(0)}} otherwise next call to {{CharSequenceInputStream#read()}} will return the remaining tail which {{bbuf}} has accumulated.
> In the attached test case the test fails, if {{dataSize = 13}} (not dividable by 10) and runs OK if {{dataSize = 20}} (dividable by 10).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (IO-356) CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13507445#comment-13507445 ] 

Gary Gregory commented on IO-356:
---------------------------------

I've added tests with @Ignore but the problem seems deeper. The fix above does not work with the tests I added (unless the tests have bugs ;)

It's not clear why we are not simply doing:

{code:java}
    /**
     * {@inheritDoc}
     * @param readlimit max read limit (ignored)
     */
    @Override
    public synchronized void mark(@SuppressWarnings("unused") int readlimit) {
        //this.mark = this.cbuf.position();
        this.cbuf.mark();
    }

    @Override
    public synchronized void reset() throws IOException {
//        if (this.mark != NO_MARK) {
//            this.cbuf.position(this.mark);
//            this.mark = NO_MARK;
//        }
        this.cbuf.reset();
    }
{code}

This does not fix anything but it does not break anything else.

If we need a mark, then we need tests to show why the solution above does not suffice.

Help wanted.

Gary
                
> CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not dividable by data size
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: IO-356
>                 URL: https://issues.apache.org/jira/browse/IO-356
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.4
>            Reporter: Dmitry Katsubo
>         Attachments: CharSequenceInputStreamTest.java
>
>
> The size effect happens when buffer size of input stream is not dividable by requested data size. The bug is hidden in {{CharSequenceInputStream#reset()}} method which should also call (I think) {{bbuf.limit(0)}} otherwise next call to {{CharSequenceInputStream#read()}} will return the remaining tail which {{bbuf}} has accumulated.
> In the attached test case the test fails, if {{dataSize = 13}} (not dividable by 10) and runs OK if {{dataSize = 20}} (dividable by 10).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira