Improve the stability of tag binding

This is mostly a preventative change than one based on actual issues encountered.

Removing from a collection that is being iterated over is not supported and should usually lead to a `ConcurrentModificationException` being thrown. Using an `Iterator` prevents this from happening.

Signed-off-by: nscuro <nscuro@protonmail.com>
This commit is contained in:
nscuro 2025-04-26 16:43:28 +02:00
parent 3c3d4865fe
commit 36d869c968
No known key found for this signature in database
3 changed files with 15 additions and 6 deletions

View file

@ -75,6 +75,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -1392,9 +1393,11 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
}
if (!keepExisting) {
for (final Tag existingTag : project.getTags()) {
final Iterator<Tag> existingTagsIterator = project.getTags().iterator();
while (existingTagsIterator.hasNext()) {
final Tag existingTag = existingTagsIterator.next();
if (!tags.contains(existingTag)) {
project.getTags().remove(existingTag);
existingTagsIterator.remove();
if (existingTag.getProjects() != null) {
existingTag.getProjects().remove(project);
}