Skip to content

java.util.ConcurrentModificationException is thrown when calling Story#removeVariableObserver(VariableObserver observer) #27

@j0rdanit0

Description

@j0rdanit0

blade-ink version

1.0.1

Description:

There is a bug in the logic for when the Story object removes a VariableObserver from all variables. This is the offending code:

// Remove observer for all variables
for (Map.Entry<String, List<VariableObserver>> obs : variableObservers.entrySet()) {
	obs.getValue().remove(observer);
	if (obs.getValue().size() == 0) {
		variableObservers.remove(obs.getKey());
	}
}

We can see that the variableObservers map is being iterated over here, but inside of the for loop there is a call to remove an element from that map. This always results in a java.util.ConcurrentModificationException being thrown.

The removals should either take place outside of the for loop, or otherwise use an Iterator to do the iteration so that the inner removal can occur without issue. https://stackoverflow.com/a/10432084

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions