avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thiruvalluvan M. G. (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-1711) JsonDecoder.skipChildren skips more than it should.
Date Sat, 16 Apr 2016 19:24:25 GMT

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

Thiruvalluvan M. G. commented on AVRO-1711:
-------------------------------------------

The fix looks good to me. But it will be nice if there is a unit test that catches the problem
and prove that the fix indeed works.

If others are busy, I'll try to work on it tomorrow.

> JsonDecoder.skipChildren skips more than it should.
> ---------------------------------------------------
>
>                 Key: AVRO-1711
>                 URL: https://issues.apache.org/jira/browse/AVRO-1711
>             Project: Avro
>          Issue Type: Bug
>    Affects Versions: 1.8.0
>            Reporter: Zoltan Farkas
>
> JsonDecoder.skipChildren() does not respect Contract, it will point to the next available
token after END_ARRAY and END_OBJECT. It should point to END_ARRAY and END_OBJECT instead
> Here is current implementation:
> {noformat}
>       @Override
>       public JsonParser skipChildren() throws IOException {
>         int level = 0;
>         do {
>           switch(elements.get(pos++).token) {
>           case START_ARRAY:
>           case START_OBJECT:
>             level++;
>             break;
>           case END_ARRAY:
>           case END_OBJECT:
>             level--;
>             break;
>           }
>         } while (level > 0);
>         return this;
>       }
> {noformat}
> Here is the documentation of what the method needs to do:
> {noformat}
>     /**
>      * Method that will skip all child tokens of an array or
>      * object token that the parser currently points to,
>      * iff stream points to 
>      * {@link JsonToken#START_OBJECT} or {@link JsonToken#START_ARRAY}.
>      * If not, it will do nothing.
>      * After skipping, stream will point to <b>matching</b>
>      * {@link JsonToken#END_OBJECT} or {@link JsonToken#END_ARRAY}
>      * (possibly skipping nested pairs of START/END OBJECT/ARRAY tokens
>      * as well as value tokens).
>      * The idea is that after calling this method, application
>      * will call {@link #nextToken} to point to the next
>      * available token, if any.
>      */
> {noformat}
> here is the implementation, fixed:
> {noformat}
>       @Override
>       public JsonParser skipChildren() throws IOException {
>         int level = 0;
>         do {
>           switch(elements.get(pos++).token) {
>           case START_ARRAY:
>           case START_OBJECT:
>             level++;
>             break;
>           case END_ARRAY:
>           case END_OBJECT:
>             level--;
>             break;
>           }
>         } while (level > 0);
>         pos--;
>         return this;
>       }
> {noformat}



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

Mime
View raw message