Updated the routing table bucket class to copy the contacts to another data structure before sending them, preventing other parts of the system from modifying the core data structure

This commit is contained in:
Joshua Kissoon 2014-05-18 15:17:36 +05:30
parent 807a9965d0
commit a9e5402697

View File

@ -194,7 +194,21 @@ public class KadBucketImpl implements KadBucket
@Override @Override
public synchronized List<Contact> getContacts() public synchronized List<Contact> getContacts()
{ {
return (this.contacts.isEmpty()) ? new ArrayList<>() : new ArrayList<>(this.contacts); final ArrayList<Contact> ret = new ArrayList<>();
/* If we have no contacts, return the blank arraylist */
if (this.contacts.isEmpty())
{
return ret;
}
/* We have contacts, lets copy put them into the arraylist and return */
for (Contact c : this.contacts)
{
ret.add(c);
}
return ret;
} }
/** /**