Use CopyOnWriteArraySet for pingFailedListeners

To prevent

java.util.ConcurrentModificationException
  at java.util.HashMap$HashIterator.nextEntry(HashMap.java:788)
  at java.util.HashMap$KeyIterator.next(HashMap.java:815)
  at org.jivesoftware.smackx.ping.PingManager.pingMyServer(PingManager.java:252)
  at org.kontalk.service.msgcenter.MessageCenterService$3.run(MessageCenterService.java:1114)
  at java.lang.Thread.run(Thread.java:818)

Thanks to Daniele Ricci for reporting this.
This commit is contained in:
Florian Schmaus 2017-02-15 20:14:41 +01:00
parent bb3eeb9af0
commit 6cfdf2bc6f
1 changed files with 3 additions and 5 deletions

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2012-2015 Florian Schmaus
* Copyright 2012-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,11 +16,10 @@
*/
package org.jivesoftware.smackx.ping;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
@ -105,8 +104,7 @@ public final class PingManager extends Manager {
defaultPingInterval = interval;
}
private final Set<PingFailedListener> pingFailedListeners = Collections
.synchronizedSet(new HashSet<PingFailedListener>());
private final Set<PingFailedListener> pingFailedListeners = new CopyOnWriteArraySet<>();
private final ScheduledExecutorService executorService;