This is an automated email from the ASF dual-hosted git repository.

RyanSkraba pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/main by this push:
     new 96389ebf4d AVRO-4253: Avoid logging datum values in 
UnresolvedUnionException message (#3764)
96389ebf4d is described below

commit 96389ebf4d03ca2ee9c59a1083cde1bcd5b307c0
Author: kunal sevkani <[email protected]>
AuthorDate: Thu May 7 22:21:15 2026 +0530

    AVRO-4253: Avoid logging datum values in UnresolvedUnionException message 
(#3764)
    
    UnresolvedUnionException previously included the string representation
    of the unresolved datum in its exception message. When this exception
    propagates to generic error handlers (e.g. in Kafka Connect runtime),
    the datum value — which may contain sensitive user data — gets written
    to log files.
    
    Replace the datum's toString() with its class name in the exception
    message. The actual datum object remains accessible via
    getUnresolvedDatum() for callers that need it for programmatic use.
---
 .../src/main/java/org/apache/avro/UnresolvedUnionException.java  | 9 +++++++--
 .../java/org/apache/avro/generic/TestGenericDatumWriter.java     | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java 
b/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java
index 8f25c2cc9a..1e11a4967a 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/UnresolvedUnionException.java
@@ -24,13 +24,14 @@ public class UnresolvedUnionException extends 
AvroRuntimeException {
   private Schema unionSchema;
 
   public UnresolvedUnionException(Schema unionSchema, Object unresolvedDatum) {
-    super("Not in union " + unionSchema + ": " + unresolvedDatum);
+    super("Not in union " + unionSchema + ": " + 
datumTypeDescription(unresolvedDatum));
     this.unionSchema = unionSchema;
     this.unresolvedDatum = unresolvedDatum;
   }
 
   public UnresolvedUnionException(Schema unionSchema, Schema.Field field, 
Object unresolvedDatum) {
-    super("Not in union " + unionSchema + ": " + unresolvedDatum + " (field=" 
+ field.name() + ")");
+    super(
+        "Not in union " + unionSchema + ": " + 
datumTypeDescription(unresolvedDatum) + " (field=" + field.name() + ")");
     this.unionSchema = unionSchema;
     this.unresolvedDatum = unresolvedDatum;
   }
@@ -42,4 +43,8 @@ public class UnresolvedUnionException extends 
AvroRuntimeException {
   public Schema getUnionSchema() {
     return unionSchema;
   }
+
+  private static String datumTypeDescription(Object datum) {
+    return datum == null ? "null" : datum.getClass().getName();
+  }
 }
diff --git 
a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java
 
b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java
index dc3661f467..03123ffcf8 100644
--- 
a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java
+++ 
b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java
@@ -56,7 +56,7 @@ public class TestGenericDatumWriter {
       new GenericDatumWriter<>(s).write(r, EncoderFactory.get().jsonEncoder(s, 
bao));
       fail();
     } catch (final UnresolvedUnionException uue) {
-      assertEquals("Not in union [\"null\",\"string\"]: 100 (field=f)", 
uue.getMessage());
+      assertEquals("Not in union [\"null\",\"string\"]: java.lang.Integer 
(field=f)", uue.getMessage());
     }
   }
 

Reply via email to