From b200a47eca60452d070ad035f0251b24a8bf2d61 Mon Sep 17 00:00:00 2001
From: alaskowski <alaskowski@ethz.ch>
Date: Thu, 25 May 2023 13:52:13 +0200
Subject: [PATCH] SSDM-13524: Added missing null-check for material type
 UpdateMaterialTypesOperationExecutor

---
 .../UpdateMaterialTypesOperationExecutor.java | 29 ++++++++++++-------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/UpdateMaterialTypesOperationExecutor.java b/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/UpdateMaterialTypesOperationExecutor.java
index d245d052a67..064cd81ab01 100644
--- a/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/UpdateMaterialTypesOperationExecutor.java
+++ b/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/UpdateMaterialTypesOperationExecutor.java
@@ -47,7 +47,8 @@ public class UpdateMaterialTypesOperationExecutor
         implements IUpdateMaterialTypesOperationExecutor
 {
     private static final List<DataTypeCode> INVALID_TYPES =
-            Arrays.asList(DataTypeCode.ARRAY_INTEGER, DataTypeCode.ARRAY_STRING, DataTypeCode.ARRAY_REAL,
+            Arrays.asList(DataTypeCode.ARRAY_INTEGER, DataTypeCode.ARRAY_STRING,
+                    DataTypeCode.ARRAY_REAL,
                     DataTypeCode.ARRAY_TIMESTAMP, DataTypeCode.JSON);
 
     @Autowired
@@ -82,26 +83,34 @@ public class UpdateMaterialTypesOperationExecutor
     {
         for (MaterialTypeUpdate materialTypeUpdate : materialTypeUpdates)
         {
-            if(materialTypeUpdate.getPropertyAssignments() != null)
+            if (materialTypeUpdate.getPropertyAssignments() != null)
             {
                 for (PropertyAssignmentCreation addedAssignments : materialTypeUpdate.getPropertyAssignments()
                         .getAdded())
                 {
-                    PropertyTypePE type =
-                            findPropertyType(context, addedAssignments.getPropertyTypeId());
-                    if (type.getType() != null && INVALID_TYPES.contains(type.getType().getCode()))
+                    if (addedAssignments.getPropertyTypeId() != null)
                     {
-                        return false;
+                        PropertyTypePE type =
+                                findPropertyType(context, addedAssignments.getPropertyTypeId());
+                        if (type.getType() != null && INVALID_TYPES.contains(
+                                type.getType().getCode()))
+                        {
+                            return false;
+                        }
                     }
                 }
                 for (PropertyAssignmentCreation setAssignments : materialTypeUpdate.getPropertyAssignments()
                         .getSet())
                 {
-                    PropertyTypePE type =
-                            findPropertyType(context, setAssignments.getPropertyTypeId());
-                    if (type.getType() != null && INVALID_TYPES.contains(type.getType().getCode()))
+                    if (setAssignments.getPropertyTypeId() != null)
                     {
-                        return false;
+                        PropertyTypePE type =
+                                findPropertyType(context, setAssignments.getPropertyTypeId());
+                        if (type.getType() != null && INVALID_TYPES.contains(
+                                type.getType().getCode()))
+                        {
+                            return false;
+                        }
                     }
                 }
             }
-- 
GitLab