Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1711

JsonDecoder.skipChildren skips more than it should.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1
    • None
    • None

    Description

      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:

            @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;
            }
      

      Here is the documentation of what the method needs to do:

          /**
           * 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.
           */
      

      here is the implementation, fixed:

            @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;
            }
      

      Attachments

        1. AVRO-1711.patch
          2 kB
          Thiruvalluvan M. G.

        Issue Links

          Activity

            People

              zolyfarkas Zoltan Farkas
              zolyfarkas Zoltan Farkas
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: