You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "clesaec (via GitHub)" <gi...@apache.org> on 2023/07/06 09:15:43 UTC

[GitHub] [avro] clesaec opened a new pull request, #2322: AVRO-2918: [java] Schema polymorphism

clesaec opened a new pull request, #2322:
URL: https://github.com/apache/avro/pull/2322

   <!--
   
   *Thank you very much for contributing to Apache Avro - we are happy that you want to help us improve Avro. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Avro a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/AVRO/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "AVRO-XXXX: [component] Title of the pull request", where *AVRO-XXXX* should be replaced by the actual issue number. 
       The *component* is optional, but can help identify the correct reviewers faster: either the language ("java", "python") or subsystem such as "build" or "doc" are good candidates.  
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests. You can [build the entire project](https://github.com/apache/avro/blob/master/BUILD.md) or just the [language-specific SDK](https://avro.apache.org/project/how-to-contribute/#unit-tests).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Every commit message references Jira issues in their subject lines. In addition, commits follow the guidelines from [How to write a good git commit message](https://chris.beams.io/posts/git-commit/)
       1. Subject is separated from body by a blank line
       1. Subject is limited to 50 characters (not including Jira issue reference)
       1. Subject does not end with a period
       1. Subject uses the imperative mood ("add", not "adding")
       1. Body wraps at 72 characters
       1. Body explains "what" and "why", not "how"
   
   -->
   
   ## What is the purpose of the change
   
   [AVRO-2918](https://issues.apache.org/jira/browse/AVRO-2918) : Add inheritance between schema, allow to define record schema as child of another.
   This PR is to explore generated java code that complete [first PR](https://github.com/apache/avro/pull/1776) that only include inheritance for IndexedRecord and schema.
   So, as code generation should have been modified, it imply lot of tests generated code.
   
   ## Verifying this change
   
   - A new unit test TestSpecificCompiler.inheritance test this new feature for generated code
   - Generated code already used for tests has been "re-generated" to ensure there is no regression.
   
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (yes)
   - If yes, how is the feature documented? (not documented)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] github-code-scanning[bot] commented on a diff in pull request #2322: AVRO-2918: [java] Schema polymorphism

Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #2322:
URL: https://github.com/apache/avro/pull/2322#discussion_r1298098555


##########
lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java:
##########
@@ -922,6 +927,61 @@
     }
   }
 
+  @Test
+  void inheritance() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+    File parentFile = new File("src/test/resources/inheritance/parent.avsc");
+    Assertions.assertTrue(parentFile.exists());
+    File childFile = new File("src/test/resources/inheritance/child.avsc");
+    SpecificCompiler.compileSchema(new File[] { parentFile, childFile }, OUTPUT_DIR);
+
+    File f1 = new File(this.OUTPUT_DIR, "Parent.java");
+    File f2 = new File(this.OUTPUT_DIR, "Child.java");
+    Assertions.assertTrue(f2.exists());
+
+    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
+    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+    StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
+
+    // This sets up the class path that the compiler will use.
+    // I've added the .jar file that contains the DoStuff interface within in it...
+    List<String> optionList = Collections.emptyList(); // Arrays.asList("-classpath", this.OUTPUT_DIR.getName());
+
+    Iterable<? extends JavaFileObject> compilationUnit = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(f1, f2));
+    JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, optionList, null,
+        compilationUnit);
+    /*********************************************************************************************
+     * Compilation Requirements
+     **/
+    if (task.call()) {
+      /**
+       * Load and execute
+       *************************************************************************************************/
+      // Create a new custom class loader, pointing to the directory that contains the
+      // compiled
+      // classes, this should point to the top of the package structure!
+      URLClassLoader classLoader = new URLClassLoader(new URL[] { this.OUTPUT_DIR.toURI().toURL() },
+          Thread.currentThread().getContextClassLoader());
+      // Load the class from the classloader by name....
+      Class<?> parentClass = classLoader.loadClass("Parent");
+      // Create a new instance...
+      Object obj = parentClass.newInstance();
+      Assertions.assertNotNull(obj);
+
+      Class<?> childClass = classLoader.loadClass("Child");
+      Assertions.assertEquals(parentClass, childClass.getSuperclass());
+      Object childObj = childClass.newInstance();

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Class.newInstance](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3132)



##########
lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java:
##########
@@ -922,6 +927,61 @@
     }
   }
 
+  @Test
+  void inheritance() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+    File parentFile = new File("src/test/resources/inheritance/parent.avsc");
+    Assertions.assertTrue(parentFile.exists());
+    File childFile = new File("src/test/resources/inheritance/child.avsc");
+    SpecificCompiler.compileSchema(new File[] { parentFile, childFile }, OUTPUT_DIR);
+
+    File f1 = new File(this.OUTPUT_DIR, "Parent.java");
+    File f2 = new File(this.OUTPUT_DIR, "Child.java");
+    Assertions.assertTrue(f2.exists());
+
+    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
+    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+    StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
+
+    // This sets up the class path that the compiler will use.
+    // I've added the .jar file that contains the DoStuff interface within in it...
+    List<String> optionList = Collections.emptyList(); // Arrays.asList("-classpath", this.OUTPUT_DIR.getName());
+
+    Iterable<? extends JavaFileObject> compilationUnit = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(f1, f2));
+    JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, optionList, null,
+        compilationUnit);
+    /*********************************************************************************************
+     * Compilation Requirements
+     **/
+    if (task.call()) {
+      /**
+       * Load and execute
+       *************************************************************************************************/
+      // Create a new custom class loader, pointing to the directory that contains the
+      // compiled
+      // classes, this should point to the top of the package structure!
+      URLClassLoader classLoader = new URLClassLoader(new URL[] { this.OUTPUT_DIR.toURI().toURL() },
+          Thread.currentThread().getContextClassLoader());
+      // Load the class from the classloader by name....
+      Class<?> parentClass = classLoader.loadClass("Parent");
+      // Create a new instance...
+      Object obj = parentClass.newInstance();

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Class.newInstance](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3131)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] github-code-scanning[bot] commented on a diff in pull request #2322: AVRO-2918: [java] Schema polymorphism

Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #2322:
URL: https://github.com/apache/avro/pull/2322#discussion_r1257365825


##########
lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java:
##########
@@ -608,21 +613,188 @@
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) MODEL$
-      .createDatumWriter(SCHEMA$);
+  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumWriter(CODER.SCHEMA$);
 
   @Override
   public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
     WRITER$.write(this, SpecificData.getEncoder(out));
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) MODEL$
-      .createDatumReader(SCHEMA$);
+  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumReader(CODER.SCHEMA$);
 
   @Override
   public void readExternal(java.io.ObjectInput in) throws java.io.IOException {
     READER$.read(this, SpecificData.getDecoder(in));
   }
 
+  @Override
+  protected boolean hasCustomCoders() {
+    return true;
+  }
+
+  @Override
+  public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException {
+    out.writeInt(this.id);
+
+    out.writeString(this.name);
+
+    long size0 = this.nicknames.size();
+    out.writeArrayStart();
+    out.setItemCount(size0);
+    long actualSize0 = 0;
+    for (java.lang.CharSequence e0 : this.nicknames) {
+      actualSize0++;
+      out.startItem();
+      out.writeString(e0);
+    }
+    out.writeArrayEnd();
+    if (actualSize0 != size0)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
+
+    long size1 = this.relatedids.size();
+    out.writeArrayStart();
+    out.setItemCount(size1);
+    long actualSize1 = 0;
+    for (java.lang.Integer e1 : this.relatedids) {
+      actualSize1++;
+      out.startItem();
+      out.writeInt(e1);
+    }
+    out.writeArrayEnd();
+    if (actualSize1 != size1)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size1 + ", but element count was " + actualSize1 + ".");
+
+    if (this.typeEnum == null) {
+      out.writeIndex(0);
+      out.writeNull();
+    } else {
+      out.writeIndex(1);
+      out.writeEnum(this.typeEnum.ordinal());
+    }
+
+  }
+
+  @Override
+  public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException {
+    org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
+    if (fieldOrder == null) {
+      this.id = in.readInt();
+
+      this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+
+      long size0 = in.readArrayStart();
+      java.util.List<java.lang.CharSequence> a0 = this.nicknames;
+      if (a0 == null) {
+        a0 = new SpecificData.Array<java.lang.CharSequence>((int) size0, CODER.SCHEMA$.getField("nicknames").schema());
+        this.nicknames = a0;
+      } else
+        a0.clear();
+      SpecificData.Array<java.lang.CharSequence> ga0 = (a0 instanceof SpecificData.Array
+          ? (SpecificData.Array<java.lang.CharSequence>) a0

Review Comment:
   ## Cast from abstract to concrete collection
   
   [List<CharSequence>](1) is cast to the concrete type [Array<CharSequence>](2), losing abstraction.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3001)



##########
lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java:
##########
@@ -96,17 +96,17 @@
 
   @Test
   void convertGenericToSpecific() {
-    GenericRecord generic = new GenericData.Record(TestRecord.SCHEMA$);
+    GenericRecord generic = new GenericData.Record(TestRecord.getClassSchema());
     generic.put("name", "foo");
     generic.put("kind", new GenericData.EnumSymbol(Kind.SCHEMA$, "BAR"));
     generic.put("hash",
         new GenericData.Fixed(MD5.SCHEMA$, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 }));
-    TestRecord specific = (TestRecord) SpecificData.get().deepCopy(TestRecord.SCHEMA$, generic);
+    TestRecord specific = (TestRecord) SpecificData.get().deepCopy(TestRecord.getClassSchema(), generic);

Review Comment:
   ## Unread local variable
   
   Variable 'TestRecord specific' is never read.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3005)



##########
lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java:
##########
@@ -608,21 +613,188 @@
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) MODEL$
-      .createDatumWriter(SCHEMA$);
+  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumWriter(CODER.SCHEMA$);
 
   @Override
   public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
     WRITER$.write(this, SpecificData.getEncoder(out));
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) MODEL$
-      .createDatumReader(SCHEMA$);
+  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumReader(CODER.SCHEMA$);
 
   @Override
   public void readExternal(java.io.ObjectInput in) throws java.io.IOException {
     READER$.read(this, SpecificData.getDecoder(in));
   }
 
+  @Override
+  protected boolean hasCustomCoders() {
+    return true;
+  }
+
+  @Override
+  public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException {
+    out.writeInt(this.id);
+
+    out.writeString(this.name);
+
+    long size0 = this.nicknames.size();
+    out.writeArrayStart();
+    out.setItemCount(size0);
+    long actualSize0 = 0;
+    for (java.lang.CharSequence e0 : this.nicknames) {
+      actualSize0++;
+      out.startItem();
+      out.writeString(e0);
+    }
+    out.writeArrayEnd();
+    if (actualSize0 != size0)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
+
+    long size1 = this.relatedids.size();
+    out.writeArrayStart();
+    out.setItemCount(size1);
+    long actualSize1 = 0;
+    for (java.lang.Integer e1 : this.relatedids) {
+      actualSize1++;
+      out.startItem();
+      out.writeInt(e1);
+    }
+    out.writeArrayEnd();
+    if (actualSize1 != size1)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size1 + ", but element count was " + actualSize1 + ".");
+
+    if (this.typeEnum == null) {
+      out.writeIndex(0);
+      out.writeNull();
+    } else {
+      out.writeIndex(1);
+      out.writeEnum(this.typeEnum.ordinal());
+    }
+
+  }
+
+  @Override
+  public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException {
+    org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
+    if (fieldOrder == null) {
+      this.id = in.readInt();
+
+      this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+
+      long size0 = in.readArrayStart();
+      java.util.List<java.lang.CharSequence> a0 = this.nicknames;
+      if (a0 == null) {
+        a0 = new SpecificData.Array<java.lang.CharSequence>((int) size0, CODER.SCHEMA$.getField("nicknames").schema());
+        this.nicknames = a0;
+      } else
+        a0.clear();
+      SpecificData.Array<java.lang.CharSequence> ga0 = (a0 instanceof SpecificData.Array
+          ? (SpecificData.Array<java.lang.CharSequence>) a0
+          : null);
+      for (; 0 < size0; size0 = in.arrayNext()) {
+        for (; size0 != 0; size0--) {
+          java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null);
+          e0 = in.readString(e0 instanceof Utf8 ? (Utf8) e0 : null);
+          a0.add(e0);
+        }
+      }
+
+      long size1 = in.readArrayStart();
+      java.util.List<java.lang.Integer> a1 = this.relatedids;
+      if (a1 == null) {
+        a1 = new SpecificData.Array<java.lang.Integer>((int) size1, CODER.SCHEMA$.getField("relatedids").schema());
+        this.relatedids = a1;
+      } else
+        a1.clear();
+      SpecificData.Array<java.lang.Integer> ga1 = (a1 instanceof SpecificData.Array
+          ? (SpecificData.Array<java.lang.Integer>) a1
+          : null);
+      for (; 0 < size1; size1 = in.arrayNext()) {
+        for (; size1 != 0; size1--) {
+          java.lang.Integer e1 = (ga1 != null ? ga1.peek() : null);
+          e1 = in.readInt();
+          a1.add(e1);
+        }
+      }
+
+      if (in.readIndex() != 1) {
+        in.readNull();
+        this.typeEnum = null;
+      } else {
+        this.typeEnum = org.apache.avro.TypeEnum.values()[in.readEnum()];
+      }
+
+    } else {
+      for (int i = 0; i < 5; i++) {
+        switch (fieldOrder[i].pos()) {
+        case 0:
+          this.id = in.readInt();
+          break;
+
+        case 1:
+          this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+          break;
+
+        case 2:
+          long size0 = in.readArrayStart();
+          java.util.List<java.lang.CharSequence> a0 = this.nicknames;
+          if (a0 == null) {
+            a0 = new SpecificData.Array<java.lang.CharSequence>((int) size0,
+                CODER.SCHEMA$.getField("nicknames").schema());
+            this.nicknames = a0;
+          } else
+            a0.clear();
+          SpecificData.Array<java.lang.CharSequence> ga0 = (a0 instanceof SpecificData.Array
+              ? (SpecificData.Array<java.lang.CharSequence>) a0

Review Comment:
   ## Cast from abstract to concrete collection
   
   [List<CharSequence>](1) is cast to the concrete type [Array<CharSequence>](2), losing abstraction.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3003)



##########
lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java:
##########
@@ -608,21 +613,188 @@
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) MODEL$
-      .createDatumWriter(SCHEMA$);
+  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumWriter(CODER.SCHEMA$);
 
   @Override
   public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
     WRITER$.write(this, SpecificData.getEncoder(out));
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) MODEL$
-      .createDatumReader(SCHEMA$);
+  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumReader(CODER.SCHEMA$);
 
   @Override
   public void readExternal(java.io.ObjectInput in) throws java.io.IOException {
     READER$.read(this, SpecificData.getDecoder(in));
   }
 
+  @Override
+  protected boolean hasCustomCoders() {
+    return true;
+  }
+
+  @Override
+  public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException {
+    out.writeInt(this.id);
+
+    out.writeString(this.name);
+
+    long size0 = this.nicknames.size();
+    out.writeArrayStart();
+    out.setItemCount(size0);
+    long actualSize0 = 0;
+    for (java.lang.CharSequence e0 : this.nicknames) {
+      actualSize0++;
+      out.startItem();
+      out.writeString(e0);
+    }
+    out.writeArrayEnd();
+    if (actualSize0 != size0)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
+
+    long size1 = this.relatedids.size();
+    out.writeArrayStart();
+    out.setItemCount(size1);
+    long actualSize1 = 0;
+    for (java.lang.Integer e1 : this.relatedids) {
+      actualSize1++;
+      out.startItem();
+      out.writeInt(e1);
+    }
+    out.writeArrayEnd();
+    if (actualSize1 != size1)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size1 + ", but element count was " + actualSize1 + ".");
+
+    if (this.typeEnum == null) {
+      out.writeIndex(0);
+      out.writeNull();
+    } else {
+      out.writeIndex(1);
+      out.writeEnum(this.typeEnum.ordinal());
+    }
+
+  }
+
+  @Override
+  public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException {
+    org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
+    if (fieldOrder == null) {
+      this.id = in.readInt();
+
+      this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+
+      long size0 = in.readArrayStart();
+      java.util.List<java.lang.CharSequence> a0 = this.nicknames;
+      if (a0 == null) {
+        a0 = new SpecificData.Array<java.lang.CharSequence>((int) size0, CODER.SCHEMA$.getField("nicknames").schema());
+        this.nicknames = a0;
+      } else
+        a0.clear();
+      SpecificData.Array<java.lang.CharSequence> ga0 = (a0 instanceof SpecificData.Array
+          ? (SpecificData.Array<java.lang.CharSequence>) a0
+          : null);
+      for (; 0 < size0; size0 = in.arrayNext()) {
+        for (; size0 != 0; size0--) {
+          java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null);
+          e0 = in.readString(e0 instanceof Utf8 ? (Utf8) e0 : null);
+          a0.add(e0);
+        }
+      }
+
+      long size1 = in.readArrayStart();
+      java.util.List<java.lang.Integer> a1 = this.relatedids;
+      if (a1 == null) {
+        a1 = new SpecificData.Array<java.lang.Integer>((int) size1, CODER.SCHEMA$.getField("relatedids").schema());
+        this.relatedids = a1;
+      } else
+        a1.clear();
+      SpecificData.Array<java.lang.Integer> ga1 = (a1 instanceof SpecificData.Array
+          ? (SpecificData.Array<java.lang.Integer>) a1

Review Comment:
   ## Cast from abstract to concrete collection
   
   [List<Integer>](1) is cast to the concrete type [Array<Integer>](2), losing abstraction.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3002)



##########
lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java:
##########
@@ -922,6 +927,60 @@
     }
   }
 
+  @Test
+  void inheritance() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+    File parentFile = new File("src/test/resources/inheritance/parent.avsc");
+    Assertions.assertTrue(parentFile.exists());
+    File childFile = new File("src/test/resources/inheritance/child.avsc");
+    SpecificCompiler.compileSchema(new File[] { parentFile, childFile }, OUTPUT_DIR);
+
+    File f1 = new File(this.OUTPUT_DIR, "Parent.java");
+    File f2 = new File(this.OUTPUT_DIR, "Child.java");
+    Assertions.assertTrue(f2.exists());
+    // String code = new String(Files.readAllBytes(f2.toPath()));
+    // System.out.println(code);
+
+    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
+    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+    StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
+
+    // This sets up the class path that the compiler will use.
+    // I've added the .jar file that contains the DoStuff interface within in it...
+    List<String> optionList = Collections.emptyList(); // Arrays.asList("-classpath", this.OUTPUT_DIR.getName());
+
+    Iterable<? extends JavaFileObject> compilationUnit = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(f1, f2));
+    JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, optionList, null,
+        compilationUnit);
+    /*********************************************************************************************
+     * Compilation Requirements
+     **/
+    if (task.call()) {
+      /**
+       * Load and execute
+       *************************************************************************************************/
+      // Create a new custom class loader, pointing to the directory that contains the
+      // compiled
+      // classes, this should point to the top of the package structure!
+      URLClassLoader classLoader = new URLClassLoader(new URL[] { this.OUTPUT_DIR.toURI().toURL() },
+          Thread.currentThread().getContextClassLoader());
+      // Load the class from the classloader by name....
+      Class<?> loadedClass = classLoader.loadClass("Parent");
+      // Create a new instance...
+      Object obj = loadedClass.newInstance();

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Class.newInstance](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3006)



##########
lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java:
##########
@@ -608,21 +613,188 @@
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) MODEL$
-      .createDatumWriter(SCHEMA$);
+  private static final org.apache.avro.io.DatumWriter<FooBarSpecificRecord> WRITER$ = (org.apache.avro.io.DatumWriter<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumWriter(CODER.SCHEMA$);
 
   @Override
   public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
     WRITER$.write(this, SpecificData.getEncoder(out));
   }
 
   @SuppressWarnings("unchecked")
-  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) MODEL$
-      .createDatumReader(SCHEMA$);
+  private static final org.apache.avro.io.DatumReader<FooBarSpecificRecord> READER$ = (org.apache.avro.io.DatumReader<FooBarSpecificRecord>) CODER.MODEL$
+      .createDatumReader(CODER.SCHEMA$);
 
   @Override
   public void readExternal(java.io.ObjectInput in) throws java.io.IOException {
     READER$.read(this, SpecificData.getDecoder(in));
   }
 
+  @Override
+  protected boolean hasCustomCoders() {
+    return true;
+  }
+
+  @Override
+  public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException {
+    out.writeInt(this.id);
+
+    out.writeString(this.name);
+
+    long size0 = this.nicknames.size();
+    out.writeArrayStart();
+    out.setItemCount(size0);
+    long actualSize0 = 0;
+    for (java.lang.CharSequence e0 : this.nicknames) {
+      actualSize0++;
+      out.startItem();
+      out.writeString(e0);
+    }
+    out.writeArrayEnd();
+    if (actualSize0 != size0)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size0 + ", but element count was " + actualSize0 + ".");
+
+    long size1 = this.relatedids.size();
+    out.writeArrayStart();
+    out.setItemCount(size1);
+    long actualSize1 = 0;
+    for (java.lang.Integer e1 : this.relatedids) {
+      actualSize1++;
+      out.startItem();
+      out.writeInt(e1);
+    }
+    out.writeArrayEnd();
+    if (actualSize1 != size1)
+      throw new java.util.ConcurrentModificationException(
+          "Array-size written was " + size1 + ", but element count was " + actualSize1 + ".");
+
+    if (this.typeEnum == null) {
+      out.writeIndex(0);
+      out.writeNull();
+    } else {
+      out.writeIndex(1);
+      out.writeEnum(this.typeEnum.ordinal());
+    }
+
+  }
+
+  @Override
+  public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException {
+    org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
+    if (fieldOrder == null) {
+      this.id = in.readInt();
+
+      this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+
+      long size0 = in.readArrayStart();
+      java.util.List<java.lang.CharSequence> a0 = this.nicknames;
+      if (a0 == null) {
+        a0 = new SpecificData.Array<java.lang.CharSequence>((int) size0, CODER.SCHEMA$.getField("nicknames").schema());
+        this.nicknames = a0;
+      } else
+        a0.clear();
+      SpecificData.Array<java.lang.CharSequence> ga0 = (a0 instanceof SpecificData.Array
+          ? (SpecificData.Array<java.lang.CharSequence>) a0
+          : null);
+      for (; 0 < size0; size0 = in.arrayNext()) {
+        for (; size0 != 0; size0--) {
+          java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null);
+          e0 = in.readString(e0 instanceof Utf8 ? (Utf8) e0 : null);
+          a0.add(e0);
+        }
+      }
+
+      long size1 = in.readArrayStart();
+      java.util.List<java.lang.Integer> a1 = this.relatedids;
+      if (a1 == null) {
+        a1 = new SpecificData.Array<java.lang.Integer>((int) size1, CODER.SCHEMA$.getField("relatedids").schema());
+        this.relatedids = a1;
+      } else
+        a1.clear();
+      SpecificData.Array<java.lang.Integer> ga1 = (a1 instanceof SpecificData.Array
+          ? (SpecificData.Array<java.lang.Integer>) a1
+          : null);
+      for (; 0 < size1; size1 = in.arrayNext()) {
+        for (; size1 != 0; size1--) {
+          java.lang.Integer e1 = (ga1 != null ? ga1.peek() : null);
+          e1 = in.readInt();
+          a1.add(e1);
+        }
+      }
+
+      if (in.readIndex() != 1) {
+        in.readNull();
+        this.typeEnum = null;
+      } else {
+        this.typeEnum = org.apache.avro.TypeEnum.values()[in.readEnum()];
+      }
+
+    } else {
+      for (int i = 0; i < 5; i++) {
+        switch (fieldOrder[i].pos()) {
+        case 0:
+          this.id = in.readInt();
+          break;
+
+        case 1:
+          this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+          break;
+
+        case 2:
+          long size0 = in.readArrayStart();
+          java.util.List<java.lang.CharSequence> a0 = this.nicknames;
+          if (a0 == null) {
+            a0 = new SpecificData.Array<java.lang.CharSequence>((int) size0,
+                CODER.SCHEMA$.getField("nicknames").schema());
+            this.nicknames = a0;
+          } else
+            a0.clear();
+          SpecificData.Array<java.lang.CharSequence> ga0 = (a0 instanceof SpecificData.Array
+              ? (SpecificData.Array<java.lang.CharSequence>) a0
+              : null);
+          for (; 0 < size0; size0 = in.arrayNext()) {
+            for (; size0 != 0; size0--) {
+              java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null);
+              e0 = in.readString(e0 instanceof Utf8 ? (Utf8) e0 : null);
+              a0.add(e0);
+            }
+          }
+          break;
+
+        case 3:
+          long size1 = in.readArrayStart();
+          java.util.List<java.lang.Integer> a1 = this.relatedids;
+          if (a1 == null) {
+            a1 = new SpecificData.Array<java.lang.Integer>((int) size1, CODER.SCHEMA$.getField("relatedids").schema());
+            this.relatedids = a1;
+          } else
+            a1.clear();
+          SpecificData.Array<java.lang.Integer> ga1 = (a1 instanceof SpecificData.Array
+              ? (SpecificData.Array<java.lang.Integer>) a1

Review Comment:
   ## Cast from abstract to concrete collection
   
   [List<Integer>](1) is cast to the concrete type [Array<Integer>](2), losing abstraction.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3004)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org