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

Avro compiler(s) should produce valid code when using reserved identifiers like 'record' in names

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.10.2
    • 1.11.0
    • java

    Description

      Java 14 introduced 'record' as a restricted type name and cannot be used for type declarations. So Avro should not generate code that uses this in its name for example classes based on a schema with name 'record'. It is probably a good idea that we reject uses of Java keywords including reserved identifiers.

      This can be reproduced easily in Avro's current codebase running the `TestSpecificCompiler` test with JDK 16.

      https://github.com/apache/avro/blob/bfe1d03d683d67cdb9a984c02c6b1eb75ffe7689/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java#L201

      public class record extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
      ^
      as of release 14, 'record' is a restricted type name and cannot be used for type declarations
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:23: error: 'record' is not allowed here
      private static final BinaryMessageEncoder<record> ENCODER =
      ^
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:24: error: 'record' is not allowed here
      new BinaryMessageEncoder<record>(MODEL$, SCHEMA$);
      ^
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:26: error: 'record' is not allowed here
      private static final BinaryMessageDecoder<record> DECODER =
      ^
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:27: error: 'record' is not allowed here
      new BinaryMessageDecoder<record>(MODEL$, SCHEMA$);
      ^
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:33: error: 'record' is not allowed here
      public static BinaryMessageEncoder<record> getEncoder() {
      ^
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:41: error: 'record' is not allowed here
      public static BinaryMessageDecoder<record> getDecoder() {
      ^
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:50: error: 'record' is not allowed here
      public static BinaryMessageDecoder<record> createDecoder(SchemaStore resolver) {
      ^
      [main] ERROR org.apache.avro.compiler.specific.TestSpecificCompiler - /tmp/junit6626196665903310578/testInvalidParameterCounts1/sample/record.java:51: error: 'record' is not allowed here
      return new BinaryMessageDecoder<record>(MODEL$, SCHEMA$, resolver);

      Attachments

        Issue Links

          Activity

            People

              rskraba Ryan Skraba
              iemejia Ismaël Mejía
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: