@@ -434,16 +434,19 @@ public void addSiblings(Integer nodeId, List<OrgChartItem> siblings) {
434434 private void onSiblingsAdded (String nodeId , JsonArray siblingIds ) {
435435 // Find the node where siblings were added
436436 OrgChartItem targetItem = getById (Integer .valueOf (nodeId ), orgChartItem );
437+ if (targetItem != null ) {
437438
438- // Convert the JsonArray to a simple list of integer IDs
439- List <Integer > newSiblingIdList = convertJsonArrayToIntegerList (siblingIds );
439+ // Convert the JsonArray to a simple list of integer IDs
440+ List <Integer > newSiblingIdList = convertJsonArrayToIntegerList (siblingIds );
440441
441- // Convert the list of IDs into a list of the actual OrgChartItem objects
442- List <OrgChartItem > newSiblingItems = newSiblingIdList .stream ()
443- .map (id -> getById (id , orgChartItem )).filter (Objects ::nonNull ).collect (Collectors .toList ());
442+ // Convert the list of IDs into a list of the actual OrgChartItem objects
443+ List <OrgChartItem > newSiblingItems =
444+ newSiblingIdList .stream ().map (id -> getById (id , orgChartItem )).filter (Objects ::nonNull )
445+ .collect (Collectors .toList ());
444446
445- // Fire the event with the parent and the fully populated list of child items
446- fireSiblingsAddedEvent (targetItem , newSiblingItems , true );
447+ // Fire the event with the parent and the fully populated list of child items
448+ fireSiblingsAddedEvent (targetItem , newSiblingItems , true );
449+ }
447450 }
448451
449452 /**
@@ -504,16 +507,19 @@ public void addChildren(Integer nodeId, List<OrgChartItem> children) {
504507 private void onChildrenAdded (String nodeId , JsonArray childIds ) {
505508 // Find the parent node where children were added
506509 OrgChartItem parentItem = getById (Integer .valueOf (nodeId ), orgChartItem );
510+ if (parentItem != null ) {
507511
508- // Convert the JsonArray to a simple list of integer IDs
509- List <Integer > newChildIdList = convertJsonArrayToIntegerList (childIds );
512+ // Convert the JsonArray to a simple list of integer IDs
513+ List <Integer > newChildIdList = convertJsonArrayToIntegerList (childIds );
510514
511- // Convert the list of IDs into a list of the actual OrgChartItem objects
512- List <OrgChartItem > newChildItems = newChildIdList .stream ().map (id -> getById (id , orgChartItem ))
513- .filter (Objects ::nonNull ).collect (Collectors .toList ());
515+ // Convert the list of IDs into a list of the actual OrgChartItem objects
516+ List <OrgChartItem > newChildItems =
517+ newChildIdList .stream ().map (id -> getById (id , orgChartItem )).filter (Objects ::nonNull )
518+ .collect (Collectors .toList ());
514519
515- // Fire the event with the parent and the fully populated list of child items
516- fireChildrenAddedEvent (parentItem , newChildItems , true );
520+ // Fire the event with the parent and the fully populated list of child items
521+ fireChildrenAddedEvent (parentItem , newChildItems , true );
522+ }
517523 }
518524
519525 /**
0 commit comments