Author: toad
Date: 2007-08-17 19:34:49 +0000 (Fri, 17 Aug 2007)
New Revision: 14765

Modified:
   trunk/freenet/src/freenet/node/PeerNode.java
   trunk/freenet/src/freenet/node/PeerNodeStatus.java
Log:
Prevent ConcurrentModificationException by copying the hashtables while holding 
the lock

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2007-08-17 19:16:40 UTC 
(rev 14764)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2007-08-17 19:34:49 UTC 
(rev 14765)
@@ -2259,14 +2259,12 @@
                }
        }

-       //FIXME: maybe return a copy insteed
-       public Hashtable getLocalNodeSentMessagesToStatistic () {
-               return localNodeSentMessageTypes;
+       public synchronized Hashtable getLocalNodeSentMessagesToStatistic () {
+               return new Hashtable(localNodeSentMessageTypes);
        }

-       //FIXME: maybe return a copy insteed
        public Hashtable getLocalNodeReceivedMessagesFromStatistic () {
-               return localNodeReceivedMessageTypes;
+               return new Hashtable(localNodeReceivedMessageTypes);
        }

        synchronized USK getARK() {

Modified: trunk/freenet/src/freenet/node/PeerNodeStatus.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNodeStatus.java  2007-08-17 19:16:40 UTC 
(rev 14764)
+++ trunk/freenet/src/freenet/node/PeerNodeStatus.java  2007-08-17 19:34:49 UTC 
(rev 14765)
@@ -108,8 +108,8 @@
                this.timeLastRoutable = peerNode.timeLastRoutable();
                this.timeLastConnectionCompleted = 
peerNode.timeLastConnectionCompleted();
                this.peerAddedTime = peerNode.getPeerAddedTime();
-               this.localMessagesReceived = new 
Hashtable(peerNode.getLocalNodeReceivedMessagesFromStatistic());
-               this.localMessagesSent = new 
Hashtable(peerNode.getLocalNodeSentMessagesToStatistic());
+               this.localMessagesReceived = 
peerNode.getLocalNodeReceivedMessagesFromStatistic();
+               this.localMessagesSent = 
peerNode.getLocalNodeSentMessagesToStatistic();
                this.hashCode = peerNode.hashCode;
                this.pReject = peerNode.getPRejected();
                this.totalBytesIn = peerNode.getTotalInputBytes();


Reply via email to