Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
j0rdanit0 opened this issue Oct 21, 2022 · 1 comment

Comments

@j0rdanit0
Copy link
Contributor

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

j0rdanit0 added a commit to j0rdanit0/blade-ink that referenced this issue Oct 21, 2022
@bladecoder
Copy link
Owner

Fixed in v1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants