fix issue with null objects in groups

This commit is contained in:
Bane Stojkovic
2026-01-19 23:22:19 +01:00
parent be16910767
commit a32ad6b733
2 changed files with 6 additions and 20 deletions
@@ -164,8 +164,12 @@ public class Project implements Serializable, Cloneable {
if (groups != null && !groups.isEmpty()) {
for (Set<IDIYComponent<?>> group : groups) {
ComponentGroup newGroup = ComponentGroup.from(group, null);
groupsEx.add(newGroup);
Set<IDIYComponent<?>> nonNullIds =
group.stream().filter(Objects::nonNull).collect(Collectors.toSet());
if (!nonNullIds.isEmpty()) {
ComponentGroup newGroup = ComponentGroup.from(group, null);
groupsEx.add(newGroup);
}
}
groups.clear();
}
@@ -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