From a32ad6b733f811c14039c0b64aeb305029fb8352 Mon Sep 17 00:00:00 2001 From: Bane Stojkovic Date: Mon, 19 Jan 2026 23:22:19 +0100 Subject: [PATCH] fix issue with null objects in groups --- .../src/main/java/org/diylc/core/Project.java | 8 ++++++-- .../java/org/diylc/presenter/Presenter.java | 18 ------------------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/diylc/diylc-core/src/main/java/org/diylc/core/Project.java b/diylc/diylc-core/src/main/java/org/diylc/core/Project.java index e58eb052..7fb8a653 100644 --- a/diylc/diylc-core/src/main/java/org/diylc/core/Project.java +++ b/diylc/diylc-core/src/main/java/org/diylc/core/Project.java @@ -164,8 +164,12 @@ public class Project implements Serializable, Cloneable { if (groups != null && !groups.isEmpty()) { for (Set> group : groups) { - ComponentGroup newGroup = ComponentGroup.from(group, null); - groupsEx.add(newGroup); + Set> nonNullIds = + group.stream().filter(Objects::nonNull).collect(Collectors.toSet()); + if (!nonNullIds.isEmpty()) { + ComponentGroup newGroup = ComponentGroup.from(group, null); + groupsEx.add(newGroup); + } } groups.clear(); } diff --git a/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java index 93e98861..9512d696 100644 --- a/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/main/java/org/diylc/presenter/Presenter.java @@ -278,8 +278,6 @@ public class Presenter implements IPlugInPort { drawingManager.clearContinuityArea(); DrawingCache.Instance.clear(); updateSelection(EMPTY_SELECTION); - // Clean up any invalid groups that may have been loaded - cleanupInvalidGroups(); messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart, filename); messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers()); @@ -2218,22 +2216,6 @@ public class Presenter implements IPlugInPort { group -> group.getComponentIds() != null && group.getComponentIds().stream() .anyMatch(id -> id != null && componentIds.contains(id))); } - - /** - * Removes invalid groups (groups with null IDs or empty sets) from the project. - * This should be called periodically to clean up corrupted groups. - */ - private void cleanupInvalidGroups() { - int initialSize = currentProject.getGroupsEx().size(); - currentProject.getGroupsEx().removeIf(group -> - group.getComponentIds() == null || - group.getComponentIds().isEmpty() || - group.getComponentIds().stream().allMatch(id -> id == null)); - int removed = initialSize - currentProject.getGroupsEx().size(); - if (removed > 0) { - LOG.warn("Removed " + removed + " invalid group(s) with null or empty component IDs"); - } - } /** * Finds all components that are grouped with the specified component. This should be called any