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

Parser symbol tree flattening is broken for recursive schemas

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.7
    • Fix Version/s: 1.8.1
    • Component/s: None
    • Labels:
      None

      Description

      Here is a unit test to reproduce:

      package org.apache.avro.io.parsing;
      
      import java.io.IOException;
      import java.util.HashMap;
      import java.util.HashSet;
      import java.util.Set;
      import junit.framework.Assert;
      import org.apache.avro.Schema;
      import org.junit.Test;
      
      
      public class SymbolTest {
      
      
          private static final String SCHEMA = "{\"type\":\"record\",\"name\":\"SampleNode\","
                  + "\"namespace\":\"org.spf4j.ssdump2.avro\",\n" +
      " \"fields\":[\n" +
      "    {\"name\":\"count\",\"type\":\"int\",\"default\":0},\n" +
      "    {\"name\":\"subNodes\",\"type\":\n" +
      "       {\"type\":\"array\",\"items\":{\n" +
      "           \"type\":\"record\",\"name\":\"SamplePair\",\n" +
      "           \"fields\":[\n" +
      "              {\"name\":\"method\",\"type\":\n" +
      "                  {\"type\":\"record\",\"name\":\"Method\",\n" +
      "                  \"fields\":[\n" +
      "                     {\"name\":\"declaringClass\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}},\n" +
      "                     {\"name\":\"methodName\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}\n" +
      "                  ]}},\n" +
      "              {\"name\":\"node\",\"type\":\"SampleNode\"}]}}}]}";
      
      
          @Test
          public void testSomeMethod() throws IOException {
      
              Schema schema = new Schema.Parser().parse(SCHEMA);
      
              Symbol root = Symbol.root(new ResolvingGrammarGenerator()
                      .generate(schema, schema, new HashMap<ValidatingGrammarGenerator.LitS, Symbol>()));
              validateNonNull(root, new HashSet<Symbol>());
          }
      
          private static void validateNonNull(final Symbol symb, Set<Symbol> seen) {
              if (seen.contains(symb)) {
                  return;
              } else {
                  seen.add(symb);
              }
              if (symb.production != null) {
                  for (Symbol s : symb.production) {
                      if (s == null) {
                          Assert.fail("invalid parsing tree should not contain nulls");
                      }
                      if (s.kind != Symbol.Kind.ROOT) {
                          validateNonNull(s, seen);;
                      }
                  }
              }
          }
      
      }
      

        Attachments

        1. AVRO-1667.2.patch
          6 kB
          Ryan Blue
        2. avro-1667.patch
          4 kB
          Zoltan Farkas

          Issue Links

            Activity

              People

              • Assignee:
                zolyfarkas Zoltan Farkas
                Reporter:
                zolyfarkas Zoltan Farkas
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: