From 0d419f651eed158d5fa855e25405dd0926e61e0a Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 25 Jan 2025 12:16:13 +0100 Subject: [PATCH] [FIX] dataJson checker is not responsive for null data pointer --- .../dataAccess/options/CheckJPA.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/org/kar/archidata/dataAccess/options/CheckJPA.java b/src/org/kar/archidata/dataAccess/options/CheckJPA.java index 9b2d7ae..d3908ec 100644 --- a/src/org/kar/archidata/dataAccess/options/CheckJPA.java +++ b/src/org/kar/archidata/dataAccess/options/CheckJPA.java @@ -5,6 +5,7 @@ import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -475,6 +476,7 @@ public class CheckJPA implements CheckFunctionInterface { if (dataJson != null && dataJson.checker() != null) { final CheckFunctionInterface checkerInstance = dataJson.checker().getDeclaredConstructor() .newInstance(); + // check if the type is a list, set, ... add(fieldName, ( final DBAccess ioDb, @@ -484,7 +486,24 @@ public class CheckJPA implements CheckFunctionInterface { final QueryOptions options) -> { // get the field of the specific element final Object tmpData = field.get(data); - checkerInstance.check(ioDb, baseName, tmpData, null, options); + // It is not the objective of this element to check if it is authorize to set NULL + if (tmpData == null) { + return; + } + if (tmpData instanceof Collection) { + final Collection tmpCollection = (Collection) tmpData; + final Object[] elements = tmpCollection.toArray(); + for (int iii = 0; iii < elements.length; iii++) { + if (elements[iii] != null) { + checkerInstance.check(ioDb, baseName + '.' + fieldName + '[' + iii + ']', + elements[iii], null, options); + } + } + + } else { + checkerInstance.check(ioDb, baseName + '.' + fieldName, tmpData, null, options); + } + }); } // keep this is last ==> take more time...