Michal Foksa created AVRO-4151:
----------------------------------

             Summary: When Union annotation includes class it annotates 
getSchema() fails with StackOverflowError. 
                 Key: AVRO-4151
                 URL: https://issues.apache.org/jira/browse/AVRO-4151
             Project: Apache Avro
          Issue Type: Bug
          Components: java
    Affects Versions: 1.11.4
            Reporter: Michal Foksa


When a class annotated with @Union includes the annotated class (itself), 
ReflectData.get().getSchema(AnnotatedClass.class) fails with StackOverflowError 
due to going into infinite loop.

Test:
{code:java}
@Union({Animal.class, Cat.class, Dog.class})
public static class Animal {}
public static class Cat extends Animal {}
public static class Dog extends Animal {}

@Test
void union_with_itself() {
  ReflectData.get().getSchema(Animal.class);
}{code}
fails with:
{code:java}
java.lang.StackOverflowError
    at jdk.proxy2/jdk.proxy2.$Proxy8.value(Unknown Source)
    at 
org.apache.avro.reflect.ReflectData.getAnnotatedUnion(ReflectData.java:810)
    at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:703)
    at 
org.apache.avro.reflect.ReflectData.getAnnotatedUnion(ReflectData.java:811)
    at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:703)
    at 
org.apache.avro.reflect.ReflectData.getAnnotatedUnion(ReflectData.java:811)
    at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:703)
    at 
org.apache.avro.reflect.ReflectData.getAnnotatedUnion(ReflectData.java:811)
    at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:703)  
.....{code}
 

I think it is valid use case. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to