diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java index b5f862d8f74..1014e5d2c11 100644 --- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java +++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java @@ -1144,6 +1144,11 @@ public boolean hasChild() { return this.childs != null && !(this.childs.isEmpty()); } + @Override + public Schema getParent() { + return null; + } + @Override public Stream visitHierarchy() { final Stream childsStream; @@ -1188,8 +1193,6 @@ public boolean equals(Object o) { if (!(o instanceof RecordSchema)) return false; RecordSchema that = (RecordSchema) o; - if (!equalCachedHash(that)) - return false; if (!equalNames(that)) return false; if (!propsEqual(that)) diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java index c0512415636..5a5971fe5df 100644 --- a/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java +++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java @@ -644,4 +644,12 @@ void add_types() { assertNotNull(f1); assertEquals(schemaRecord1, f1.schema()); } + + @Test + void cycleRecord() { + String cycledSchema = " { \"type\": \"record\", \"name\": \"type1\", \n" + " \"fields\": [\n" + + " { \"name\": \"f1\", \"type\": {\"type\": \"array\", \"items\": \"type1\" } }\n" + " ]\n" + " }"; + Schema schema = new Schema.Parser().parse(cycledSchema); + Assertions.assertSame(schema, schema.getField("f1").schema().getElementType()); + } } diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java index 1ae9f0e6788..6df0cf612bf 100644 --- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java +++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java @@ -1412,9 +1412,11 @@ public void setOutputCharacterEncoding(String outputCharacterEncoding) { this.outputCharacterEncoding = outputCharacterEncoding; } - public String getSchemaParentClass(boolean isError) { - if (isError) { + public String getSchemaParentClass(Schema schema) { + if (schema.isError()) { return this.errorSpecificClass; + } else if (schema.getParent() != null) { + return schema.getParent().getFullName(); } else { return this.recordSpecificClass; } diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm index 904ab4a92bc..5d1998787b6 100755 --- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm +++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm @@ -36,11 +36,7 @@ import org.apache.avro.message.SchemaStore; @$annotation #end @org.apache.avro.specific.AvroGenerated -#if ($schema.class.simpleName == "ExtendedRecordSchema") -public class ${this.mangleTypeIdentifier($schema.getName())} extends ${schema.getParent().getFullName()} implements org.apache.avro.specific.SpecificRecord { -#else -public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getSchemaParentClass($schema.isError())} implements org.apache.avro.specific.SpecificRecord { -#end +public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getSchemaParentClass($schema)} implements org.apache.avro.specific.SpecificRecord { private static final long serialVersionUID = ${this.fingerprint64($schema)}L; #set ($schemaString = $this.javaSplit($schema.toString()))