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

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


The following commit(s) were added to refs/heads/main by this push:
     new a4f7ef9799 NIFI-15589 Added UUID Type compatibility check to 
DataTypeUtils (#10892)
a4f7ef9799 is described below

commit a4f7ef9799c038915451f42cfdf4329340030d2a
Author: Pierre Villard <[email protected]>
AuthorDate: Fri Feb 13 22:14:02 2026 +0100

    NIFI-15589 Added UUID Type compatibility check to DataTypeUtils (#10892)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../serialization/record/util/DataTypeUtils.java   | 38 ++++++++++++++++++++--
 .../serialization/record/TestDataTypeUtils.java    | 22 +++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git 
a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
 
b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
index 0e7b0c9b91..94a6936eee 100644
--- 
a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
+++ 
b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
@@ -260,7 +260,7 @@ public class DataTypeUtils {
             }
             case String string -> {
                 try {
-                    return UUID.fromString(string);
+                    return UUID.fromString(string.trim());
                 } catch (Exception ex) {
                     throw new 
IllegalTypeConversionException(String.format("Could not parse %s into a UUID", 
value), ex);
                 }
@@ -313,13 +313,13 @@ public class DataTypeUtils {
             case TIME -> isTimeTypeCompatible(value, dataType.getFormat());
             case TIMESTAMP -> isTimestampTypeCompatible(value, 
dataType.getFormat());
             case STRING -> isStringTypeCompatible(value);
+            case UUID -> isUUIDTypeCompatible(value);
             case ENUM -> isEnumTypeCompatible(value, (EnumDataType) dataType);
             case MAP -> isMapTypeCompatible(value);
             case CHOICE -> {
                 final DataType chosenDataType = chooseDataType(value, 
(ChoiceDataType) dataType);
                 yield chosenDataType != null;
             }
-            default -> false;
         };
     }
 
@@ -1190,6 +1190,40 @@ public class DataTypeUtils {
         return isDateTypeCompatible(value, format);
     }
 
+    public static boolean isUUIDTypeCompatible(final Object value) {
+        if (value == null) {
+            return false;
+        }
+
+        if (value instanceof UUID) {
+            return true;
+        }
+
+        if (value instanceof byte[] bytes) {
+            return bytes.length == 16;
+        }
+
+        if (value instanceof Byte[] array) {
+            return array.length == 16;
+        }
+
+        if (value instanceof String stringValue) {
+            final String trimmed = stringValue.trim();
+            if (trimmed.isEmpty()) {
+                return false;
+            }
+
+            try {
+                UUID.fromString(trimmed);
+                return true;
+            } catch (final IllegalArgumentException e) {
+                return false;
+            }
+        }
+
+        return false;
+    }
+
     public static BigInteger toBigInt(final Object value, final String 
fieldName) {
         switch (value) {
             case null -> {
diff --git 
a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java
 
b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java
index a167f6ce4d..37f7445c33 100644
--- 
a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java
+++ 
b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java
@@ -1223,4 +1223,26 @@ public class TestDataTypeUtils {
         assertNull(DataTypeUtils.toLong("", fieldName));
         assertNull(DataTypeUtils.toShort("", fieldName));
     }
+
+    @Test
+    void testUuidCompatibilityAcrossSupportedRepresentations() {
+        final UUID uuid = UUID.randomUUID();
+        assertTrue(DataTypeUtils.isUUIDTypeCompatible(uuid));
+        assertTrue(DataTypeUtils.isUUIDTypeCompatible(uuid.toString()));
+        assertTrue(DataTypeUtils.isUUIDTypeCompatible(" " + uuid + " "));
+
+        final byte[] uuidBytes = new byte[16];
+        Arrays.fill(uuidBytes, (byte) 1);
+        assertTrue(DataTypeUtils.isUUIDTypeCompatible(uuidBytes));
+
+        final Byte[] boxedBytes = new Byte[16];
+        Arrays.fill(boxedBytes, (byte) 2);
+        assertTrue(DataTypeUtils.isUUIDTypeCompatible(boxedBytes));
+
+        assertFalse(DataTypeUtils.isUUIDTypeCompatible(null));
+        assertFalse(DataTypeUtils.isUUIDTypeCompatible(new byte[15]));
+        assertFalse(DataTypeUtils.isUUIDTypeCompatible(new Byte[15]));
+        assertFalse(DataTypeUtils.isUUIDTypeCompatible("not-a-uuid"));
+        assertFalse(DataTypeUtils.isUUIDTypeCompatible(""));
+    }
 }

Reply via email to