[ 
https://issues.apache.org/jira/browse/JOHNZON-18?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14196676#comment-14196676
 ] 

Hendrik Saly commented on JOHNZON-18:
-------------------------------------

second patch looks good but when i try to test this seems the 
ava.io.InputStreamReader cannot handle it

{code}
javax.json.stream.JsonParsingException: Unexpected IO exception on 
[lineNumber=1, columnNumber=1, streamOffset=0]
        at 
org.apache.johnzon.core.JsonStreamParserImpl.uexio(JsonStreamParserImpl.java:968)
        at 
org.apache.johnzon.core.JsonStreamParserImpl.readNextChar(JsonStreamParserImpl.java:278)
        at 
org.apache.johnzon.core.JsonStreamParserImpl.readNextNonWhitespaceChar(JsonStreamParserImpl.java:302)
        at 
org.apache.johnzon.core.JsonStreamParserImpl.next(JsonStreamParserImpl.java:337)
        at 
org.apache.johnzon.core.JsonParserTest.assertSimple(JsonParserTest.java:69)
        at 
org.apache.johnzon.core.JsonParserTest.simpleAttempting(JsonParserTest.java:248)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.io.IOException: Underlying input stream returned zero bytes
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:288)
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
        at java.io.InputStreamReader.read(InputStreamReader.java:184)
        at 
org.apache.johnzon.core.JsonStreamParserImpl.readNextChar(JsonStreamParserImpl.java:270)
        ... 27 more
{code}

tested wit something like this (try to simulate an inpustream with sometimes 
returns 0)
{code}
class AttemptingInputStream extends ByteArrayInputStream {
        
        private boolean flip = true;

        public AttemptingInputStream(byte[] buf) {
            super(buf);
            
        }

        @Override
        public synchronized int read(byte b[], int off, int len) {
            
            flip = !flip;
            
            if(flip) {
                return 0;
            }
            
            if (b == null) {
                throw new NullPointerException();
            } else if (off < 0 || 1 > b.length - off) {
                throw new IndexOutOfBoundsException();
            }
         
            if (pos >= count) {
                return -1;
            }

            int avail = count - pos;
            
            if (avail == 0) {
                return 0;
            }
            System.arraycopy(buf, pos, b, off, 1);
            pos++;
            return 1;
        }
    }
{code}


> JsonStreamParserImpl not filling up buffer consistently
> -------------------------------------------------------
>
>                 Key: JOHNZON-18
>                 URL: https://issues.apache.org/jira/browse/JOHNZON-18
>             Project: Johnzon
>          Issue Type: Bug
>          Components: Core
>            Reporter: Thiago Veronezi
>            Assignee: Hendrik Saly
>             Fix For: 0.2-incubating
>
>         Attachments: 
> JsonStreamParserImpl_not_filling_up_buffer_consistently.patch, 
> JsonStreamParserImpl_not_filling_up_buffer_consistently_2.patch, 
> JsonStreamParserImpl_not_filling_up_buffer_consistently_3.patch
>
>
> This is related to the issue discussed 
> [here|https://issues.apache.org/jira/browse/JOHNZON-17]. Basically, the 
> "read" method might not read all the bytes at once. We need to make sure to 
> read at least one until we reach the value "-1".



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to