You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Faisal Feroz (JIRA)" <ji...@apache.org> on 2017/11/28 18:10:00 UTC

[jira] [Created] (AVRO-2108) @Stringable annotation should be processed before creating the schema

Faisal Feroz created AVRO-2108:
----------------------------------

             Summary: @Stringable annotation should be processed before creating the schema
                 Key: AVRO-2108
                 URL: https://issues.apache.org/jira/browse/AVRO-2108
             Project: Avro
          Issue Type: Bug
    Affects Versions: 1.8.2
            Reporter: Faisal Feroz


In {{org.apache.avro.reflect.ReflectData::createFieldSchema}} the following code is processing Stringable after explicitly creating a schema
{code:java}
Schema schema = createSchema(field.getGenericType(), names);
if (field.isAnnotationPresent(Stringable.class)) {      // Stringable
  schema = Schema.create(Schema.Type.STRING);
}
{code}
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
{code:java}
Schema schema = null;
if (field.isAnnotationPresent(Stringable.class)) {      // Stringable
  schema = Schema.create(Schema.Type.STRING);
} else {
  schema = createSchema(field.getGenericType(), names);
}
{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)