You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org> on 2025/07/18 11:37:32 UTC

Re: [PR] AVRO-4165: [java] ability to specify AvroEncode on a class [avro]

github-advanced-security[bot] commented on code in PR #3425:
URL: https://github.com/apache/avro/pull/3425#discussion_r2215831873


##########
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java:
##########
@@ -1042,4 +1045,36 @@
     }
     return super.newRecord(old, schema);
   }
+
+  public CustomEncoding getCustomEncoding(Schema schema) {
+
+    return this.encoderCache.computeIfAbsent(schema, this::populateEncoderCache).get();
+  }
+
+  private CustomEncodingWrapper populateEncoderCache(Schema schema) {
+    var enc = ReflectionUtil.getAvroEncode(getClass(schema));
+    if (enc != null) {
+      try {
+        return new CustomEncodingWrapper(enc.using().getDeclaredConstructor().newInstance());
+      } catch (Exception e) {
+        throw new AvroRuntimeException("Could not instantiate custom Encoding");
+      }
+    }
+    return new CustomEncodingWrapper(null);
+  }
+
+  private class CustomEncodingWrapper {

Review Comment:
   ## Inner class could be static
   
   CustomEncodingWrapper should be made static, since the enclosing instance is not used.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/3339)



-- 
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