Philipp Schirmer created AVRO-4237:
--------------------------------------

             Summary: Compiling a record schema with field name result fails
                 Key: AVRO-4237
                 URL: https://issues.apache.org/jira/browse/AVRO-4237
             Project: Apache Avro
          Issue Type: Bug
          Components: java
    Affects Versions: 1.12.1
            Reporter: Philipp Schirmer
         Attachments: MyRecord.java

When compiling a SpecificRecord from a record schema with a field called 
"result", the generated Java code does not compile.
{code:java}
final Schema schema = SchemaBuilder.record("MyRecord")
        .fields()
        .nullableString("result", null)
        .endRecord();
final SpecificCompiler compiler = new SpecificCompiler(schema);
compiler.compileToDestination(null, new File("src/test/java")); {code}
The generated hashCode method cannot be compiled because the field accessor is 
not prefixed with this and is thus mistaken for the local variable.
{code:java}
@Override
public int hashCode() {
  int result = 1;
  result = 31 * result + (result == null ? 0 : result.hashCode());
  return result;
} {code}
This problem does not occur in 1.12.0 because hashCode is not generated but 
inherited from a super class instead. The behavior also does not change if the 
result field is non-nullable. The null check is still generated.



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

Reply via email to