diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2009-03-02 10:46:18 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2009-03-02 10:46:18 +0000 |
commit | 6d6d1b9cd68fa1acbfa6421d5e669c9b44536e97 (patch) | |
tree | aaff5f57099e30c17a3d69f9e27455a7949a310d /src/net/java/sip/communicator/impl/protocol/zeroconf/BonjourService.java | |
parent | 965f3aa65780bfe8078a3a2bbdb725222f0f269e (diff) | |
download | jitsi-6d6d1b9cd68fa1acbfa6421d5e669c9b44536e97.zip jitsi-6d6d1b9cd68fa1acbfa6421d5e669c9b44536e97.tar.gz jitsi-6d6d1b9cd68fa1acbfa6421d5e669c9b44536e97.tar.bz2 |
Fixes possible NullPointerExceptions, incorrect code. Removes fields, marks other fields private and final.
Diffstat (limited to 'src/net/java/sip/communicator/impl/protocol/zeroconf/BonjourService.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/zeroconf/BonjourService.java | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/BonjourService.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/BonjourService.java index 2139e7e..5e896d3 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/BonjourService.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/BonjourService.java @@ -9,9 +9,10 @@ package net.java.sip.communicator.impl.protocol.zeroconf; import java.io.*; import java.net.*; import java.util.*; -import net.java.sip.communicator.util.*; -import net.java.sip.communicator.service.protocol.*; + import net.java.sip.communicator.impl.protocol.zeroconf.jmdns.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; /** * Class dealing with JmDNS and treating all the @@ -33,7 +34,8 @@ public class BonjourService extends Thread private ServiceInfo service; private boolean dead = false; - private Vector contacts = new Vector(); + private final List<ContactZeroconfImpl> contacts + = new Vector<ContactZeroconfImpl>(); private ProtocolProviderServiceZeroconfImpl pps; OperationSetPersistentPresenceZeroconfImpl opSetPersPresence; @@ -587,7 +589,7 @@ public class BonjourService extends Thread * * @return a java.util.Iterator over all contacts */ - public Iterator contacts() + public Iterator<ContactZeroconfImpl> contacts() { return contacts.iterator(); } @@ -598,6 +600,9 @@ public class BonjourService extends Thread */ public void addContact(ContactZeroconfImpl contact) { + if (contact == null) + throw new IllegalArgumentException("contact"); + synchronized(contacts) { contacts.add(contact); @@ -617,17 +622,15 @@ public class BonjourService extends Thread synchronized(contacts) { - Iterator contactsIter = contacts(); + Iterator<ContactZeroconfImpl> contactsIter = contacts(); while (contactsIter.hasNext()) { - ContactZeroconfImpl contact = - (ContactZeroconfImpl)contactsIter.next(); + ContactZeroconfImpl contact = contactsIter.next(); //System.out.println("ZEROCNF: Comparing "+id+ " "+ip+ //" with "+ contact.getAddress()+ " " + contact.getIpAddress()); if (((contact.getAddress().equals(id)) || (id == null)) - && ((contact.getIpAddress().equals(ip)) || (ip == null)) - && (contact != null)) + && ((contact.getIpAddress().equals(ip)) || (ip == null))) return contact; } @@ -649,11 +652,10 @@ public class BonjourService extends Thread { synchronized(contacts) { - Iterator contactsIter = contacts(); + Iterator<ContactZeroconfImpl> contactsIter = contacts(); while (contactsIter.hasNext()) { - ContactZeroconfImpl contact = - (ContactZeroconfImpl)contactsIter.next(); + ContactZeroconfImpl contact = contactsIter.next(); if (((contact.getAddress().equals(id)) || (id == null)) &&((contact.getIpAddress().equals(ip)) || (ip == null))) { |