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

UnsupportedOperationException on .removeTS3Listeners #294

Closed
greg2010 opened this issue Nov 26, 2018 · 3 comments
Closed

UnsupportedOperationException on .removeTS3Listeners #294

greg2010 opened this issue Nov 26, 2018 · 3 comments
Labels

Comments

@greg2010
Copy link

Hello,

I'm trying to remove an event listener registered via TS3ApiAsync.addTS3Listeners and getting UnsupportedOperationException.
Stacktrace:

java.lang.UnsupportedOperationException: null
	at java.util.concurrent.CopyOnWriteArrayList$COWIterator.remove(CopyOnWriteArrayList.java:1178)
	at com.github.theholywaffle.teamspeak3.EventManager.removeListeners(EventManager.java:72)
	at com.github.theholywaffle.teamspeak3.TS3ApiAsync.removeTS3Listeners(TS3ApiAsync.java:4146)
	at org.kys.cerberus.clients.TeamspeakClient$JoinListener.$anonfun$onClientJoin$3(TeamspeakClient.scala:71)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:654)
	at scala.util.Success.$anonfun$map$1(Try.scala:251)
	at scala.util.Success.map(Try.scala:209)
	at scala.concurrent.Future.$anonfun$map$1(Future.scala:288)
	at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
	at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
	at scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:60)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala)
	at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

I've done cursory search and it seems like the tasks array is backed by Java's CopyOnWriteArrayList. The iterator in CopyOnWriteArrayList does not implement .remove, and so the exception is thrown.
Javadoc: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArrayList.html#iterator--

The iterator does NOT support the remove method.

@rogermb rogermb added the bug label Nov 26, 2018
@rogermb
Copy link
Collaborator

rogermb commented Nov 26, 2018

Yup, that's a bug. I'll get this fixed for the next release. Also, thanks for doing the research on the Iterator's remove method.

It's kind of amazing that this has been broken for 1.5 years and you're the first one to notice (and report) this bug 😄

As a workaround for the time being, you could probably just add an enabled boolean to your listeners 😃

@kaerns
Copy link

kaerns commented Aug 16, 2019

guess i'm the second to notice this, 8 months after the fix still not in a stable release ¯_(ツ)_/¯

@rogermb
Copy link
Collaborator

rogermb commented May 28, 2021

Fixed in 4c34205 and finally released in v1.3.0 🎉

Sorry about the delay!

@rogermb rogermb closed this as completed May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants