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

@Stringable annotation should be processed before creating the schema

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.8.2
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      In org.apache.avro.reflect.ReflectData::createFieldSchema the following code is processing Stringable after explicitly creating a schema

      Schema schema = createSchema(field.getGenericType(), names);
      if (field.isAnnotationPresent(Stringable.class)) {      // Stringable
        schema = Schema.create(Schema.Type.STRING);
      }
      

      https://github.com/apache/avro/blob/3af404efb31a1dc2fd720384ef9a3f7326c2d303/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java#L748

      The above code has a side effect when @Stringable annotation is placed over a Generic Type like ID which results in Unknown Type ID since the schema is created first which causes the error.

      Changing the code to following would fix this. Also it would also act as a micro optimization of the code as the generated schema is overwritten if stringable annotation is preset

      Schema schema = null;
      if (field.isAnnotationPresent(Stringable.class)) {      // Stringable
        schema = Schema.create(Schema.Type.STRING);
      } else {
        schema = createSchema(field.getGenericType(), names);
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                FaisalFeroz Faisal Feroz
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: