@@ -400,7 +400,7 @@ private void appendItemsToParent(OrgChartItem parentNode, List<OrgChartItem> ite
400400 * This must not be the root node's ID.
401401 * @param siblings a list of {@link OrgChartItem} objects to be added as siblings
402402 * @throws IllegalArgumentException if the {@code nodeId} belongs to the root node of the chart,
403- * as the root cannot have siblings
403+ * as the root cannot have siblings or if the {@code nodeId} is not found in the chart
404404 */
405405 public void addSiblings (Integer nodeId , List <OrgChartItem > siblings ) {
406406 // First check if selected node is not the root node
@@ -416,6 +416,8 @@ public void addSiblings(Integer nodeId, List<OrgChartItem> siblings) {
416416 // Update parent's children list with the new siblings
417417 appendItemsToParent (parentNode , siblings );
418418 }
419+ } else {
420+ throw new IllegalArgumentException ("Node not found: " + nodeId );
419421 }
420422
421423 // Update the visual representation by calling the client-side method addSiblings
@@ -482,16 +484,18 @@ protected void fireSiblingsAddedEvent(OrgChartItem item, List<OrgChartItem> newS
482484 *
483485 * @param nodeId the ID of the parent node to which the new children will be added
484486 * @param children a list of {@link OrgChartItem} objects to be added as new children
487+ * @throws IllegalArgumentException if the {@code nodeId} is not found in the chart
485488 */
486489 public void addChildren (Integer nodeId , List <OrgChartItem > children ) {
487490 // Update the internal data structure
488491 OrgChartItem targetNode = getById (nodeId , orgChartItem );
492+ if (targetNode == null ) {
493+ throw new IllegalArgumentException ("Node not found: " + nodeId );
494+ }
489495 boolean currentChildrenEmpty =
490496 targetNode .getChildren () == null || targetNode .getChildren ().isEmpty ();
491- if (targetNode != null ) {
492- // Add new children while preserving existing ones
493- appendItemsToParent (targetNode , children );
494- }
497+ // Add new children while preserving existing ones
498+ appendItemsToParent (targetNode , children );
495499
496500 // Update the visual representation
497501 String itemsJson = convertToJsonObj (children );
@@ -555,6 +559,7 @@ protected void fireChildrenAddedEvent(OrgChartItem item, List<OrgChartItem> newC
555559 *
556560 * @param nodeId the ID of the node to remove. All children and subsequent descendants of this
557561 * node will also be removed from the chart.
562+ * @throws IllegalArgumentException if the {@code nodeId} is not found in the chart
558563 */
559564 public void removeNodes (Integer nodeId ) {
560565 // Find the node set for removal
@@ -577,6 +582,8 @@ public void removeNodes(Integer nodeId) {
577582
578583 // Update the visual representation
579584 this .getElement ().executeJs ("this.removeNodes($0)" , nodeId );
585+ } else {
586+ throw new IllegalArgumentException ("Node not found: " + nodeId );
580587 }
581588 }
582589
@@ -674,6 +681,7 @@ protected void fireParentAddedEvent(OrgChartItem newParent, boolean fromClient)
674681 * @param newDataItem an {@link OrgChartItem} containing the new data to be merged. The ID of this
675682 * item is ignored; only its other properties (name, title, custom data, etc) are used for
676683 * the update.
684+ * @throws IllegalArgumentException if the {@code nodeId} is not found in the chart
677685 */
678686 public void updateNode (Integer nodeId , OrgChartItem newDataItem ) {
679687 OrgChartItem nodeToUpdate = getById (nodeId , this .orgChartItem );
@@ -698,6 +706,8 @@ public void updateNode(Integer nodeId, OrgChartItem newDataItem) {
698706 // Call the client-side JS function to update the visual representation
699707 String newDataJson = convertToJsonObj (newDataItem );
700708 this .getElement ().executeJs ("this.updateNode($0, $1)" , nodeId , newDataJson );
709+ } else {
710+ throw new IllegalArgumentException ("Node not found: " + nodeId );
701711 }
702712 }
703713
0 commit comments