beanbeanjuice / cafeBot

A Discord bot! It has a currency system, cafe menu, poll and raffle system, and much more! It also has interaction commands such as hugging and smiling, but also commands for getting cafe memes, and soon to be more!
https://www.beanbeanjuice.com
GNU General Public License v3.0
9 stars 3 forks source link

[BUG] Concurrent Modification Exception in PollHandler #490

Open beanbeanjuice opened 2 years ago

beanbeanjuice commented 2 years ago

Describe the Bug

[04:31:02 PM UTC] [com.beanbeanjuice.utility.handler.CountingHandler/OKAY]: Successfully Cached Counting Information.
[04:31:02 PM UTC] [java.util.TimerThread/WARN]: Unhandled Exception: null
[04:31:02 PM UTC] [com.beanbeanjuice.utility.section.moderation.raffle.RaffleHandler/OKAY]: Successfully Retrieved All Raffles...
java.util.ConcurrentModificationException
    at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013)
    at java.base/java.util.ArrayList$Itr.next(ArrayList.java:967)
    at com.beanbeanjuice.utility.section.moderation.poll.PollHandler$1.lambda$run$3(PollHandler.java:61)
    at java.base/java.util.HashMap.forEach(HashMap.java:1425)
    at com.beanbeanjuice.utility.section.moderation.poll.PollHandler$1.run(PollHandler.java:52)
    at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
    at java.base/java.util.TimerThread.run(Timer.java:506)
[04:31:03 PM UTC] [com.beanbeanjuice.Bot/OKAY]: The bot is online!

Checklist:

TannersAndRodents commented 2 years ago

Hi, thanks for this great bot!

To me, it seems like we're trying to remove an element from an ArrayList while iterating through the list. This would be my idea for a solution: https://github.com/TannersAndRodents/cafeBot/commit/44733f9afa121463ea6981f6c535e898824f5858 However, there could be a better workaround I'm not familiar with (Maybe using an iterator directly).

I'm new to Discord bots so I could not test my idea, but I hope it is helpful.

beanbeanjuice commented 2 years ago

Hi, thanks for this great bot!

To me, it seems like we're trying to remove an element from an ArrayList while iterating through the list. This would be my idea for a solution: TannersAndRodents@44733f9 However, there could be a better workaround I'm not familiar with (Maybe using an iterator directly).

I'm new to Discord bots so I could not test my idea, but I hope it is helpful.

Thank you! Yeah, I created this section of the bot a long time ago, and it is indeed due for a complete refactor. This workaround looks not only cleanerbut also should stop the issues I've been having specifically with this class.