diff --git a/src/net/java/sip/communicator/impl/configuration/xml/XMLConfUtils.java b/src/net/java/sip/communicator/impl/configuration/xml/XMLConfUtils.java index 05439600c..613cb6e3f 100644 --- a/src/net/java/sip/communicator/impl/configuration/xml/XMLConfUtils.java +++ b/src/net/java/sip/communicator/impl/configuration/xml/XMLConfUtils.java @@ -52,20 +52,22 @@ public static Element getChildElementByChain(Element parent, */ public static Element createLastPathComponent(Document doc, String[] path) { + if (doc == null) + throw new IllegalArgumentException("doc must not be null"); + if (path == null) + throw new IllegalArgumentException("path must not be null"); + Element parent = (Element)doc.getFirstChild(); - if( path == null - || parent == null - || doc == null) - throw new IllegalArgumentException( - "Document parent and path must not be null"); + if (parent == null) + throw new IllegalArgumentException("parentmust not be null"); Element e = parent; - for(int i=0; i < path.length; i++) + for (String pathEl : path) { - Element newEl = findChild(e, path[i]); - if(newEl == null) + Element newEl = findChild(e, pathEl); + if (newEl == null) { - newEl = doc.createElement(path[i]); + newEl = doc.createElement(pathEl); e.appendChild(newEl); } e = newEl; diff --git a/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java b/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java index f1412d48e..5e9de285c 100644 --- a/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java +++ b/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java @@ -42,40 +42,40 @@ public class MetaContactListServiceImpl /** * The list of protocol providers that we're currently aware of. */ - private Map currentlyInstalledProviders + private final Map currentlyInstalledProviders = new Hashtable(); /** * The root of the meta contact list. */ - MetaContactGroupImpl rootMetaGroup + final MetaContactGroupImpl rootMetaGroup = new MetaContactGroupImpl("RootMetaContactGroup", "RootMetaContactGroup"); /** * The event handler that will be handling our subscription events. */ - ContactListSubscriptionListener clSubscriptionEventHandler + private final ContactListSubscriptionListener clSubscriptionEventHandler = new ContactListSubscriptionListener(); /** * The event handler that will be handling group events. */ - ContactListGroupListener clGroupEventHandler + private final ContactListGroupListener clGroupEventHandler = new ContactListGroupListener(); /** * The number of milliseconds to wait for confirmations of account * modifications before deciding to drop. */ - public static int CONTACT_LIST_MODIFICATION_TIMEOUT = 10000; + public static final int CONTACT_LIST_MODIFICATION_TIMEOUT = 10000; /** * Listeners interested in events dispatched upon modification of the meta * contact list. */ private final Vector metaContactListListeners - = new Vector(); + = new Vector(); /** * Contains (as keys) MetaContactGroup names that are currently @@ -87,7 +87,7 @@ public class MetaContactListServiceImpl * carries a name present in this table and is issued by one of the * providers mapped against this groupName. */ - private Hashtable> + private final Hashtable> groupEventIgnoreList = new Hashtable>(); @@ -101,7 +101,7 @@ public class MetaContactListServiceImpl * carries a name present in this table and is issued by one of the * providers mapped against this groupName. */ - private Hashtable> + private final Hashtable> contactEventIgnoreList = new Hashtable>(); @@ -109,7 +109,7 @@ public class MetaContactListServiceImpl * The instance of the storage manager which is handling the local copy of * our contact list. */ - private MclStorageManager storageManager = new MclStorageManager(); + private final MclStorageManager storageManager = new MclStorageManager(); /** * Creates an instance of this class. @@ -237,10 +237,7 @@ public void stop(BundleContext bc) } } currentlyInstalledProviders.clear(); - if(storageManager != null) - { - storageManager.stop(); - } + storageManager.stop(); } /** diff --git a/src/net/java/sip/communicator/impl/gui/customcontrols/wizard/Wizard.java b/src/net/java/sip/communicator/impl/gui/customcontrols/wizard/Wizard.java index 404347327..c6feac865 100644 --- a/src/net/java/sip/communicator/impl/gui/customcontrols/wizard/Wizard.java +++ b/src/net/java/sip/communicator/impl/gui/customcontrols/wizard/Wizard.java @@ -248,7 +248,10 @@ public void setCurrentPage(Object id) // the dialog. if (id == null) + { close(Wizard.ERROR_RETURN_CODE); + return; + } WizardPage oldPanelDescriptor = wizardModel.getCurrentWizardPage(); if (oldPanelDescriptor != null) diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java b/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java index 1dd3e6139..2fb851155 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java @@ -216,7 +216,7 @@ public void showHistoryByKeyword(String keyword) */ private HTMLDocument createHistory(Collection historyRecords) { - if(historyRecords.size() > 0) { + if((historyRecords != null) && (historyRecords.size() > 0)) { Iterator i = historyRecords.iterator(); String processedMessage = ""; @@ -402,12 +402,10 @@ else if(historyContact instanceof ChatRoomWrapper) new Date(System.currentTimeMillis())); } - Object[] msgArray = msgList.toArray(); - Date date = null; - - for (int i = 0; i < msgArray.length; i ++) + if (msgList != null) + for (Object o : msgList) { - Object o = msgArray[i]; + Date date = null; if (o instanceof MessageDeliveredEvent) { @@ -449,7 +447,7 @@ else if (o instanceof ChatRoomMessageDeliveredEvent) } } - if(msgArray.length > 0) + if((msgList != null) && (msgList.size() > 0)) { Runnable updateDatesPanel = new Runnable() { public void run() { @@ -477,9 +475,8 @@ public void run() { */ private class MessagesLoader extends Thread { - private Collection msgList; - private Date startDate; - private Date endDate; + private final Date startDate; + private final Date endDate; /** * Creates a MessageLoader thread charged to load history messages in @@ -496,6 +493,8 @@ public MessagesLoader (Date startDate, Date endDate) public void run() { + final Collection msgList; + if(historyContact instanceof MetaContact) { msgList = msgHistory.findByPeriod( @@ -512,6 +511,8 @@ else if (historyContact instanceof ChatRoomWrapper) msgList = msgHistory.findByPeriod( chatRoomWrapper.getChatRoom(), startDate, endDate); } + else + msgList = null; Runnable updateMessagesPanel = new Runnable() { @@ -534,8 +535,7 @@ public void run() */ private class KeywordDatesLoader extends Thread { private Vector keywordDatesVector = new Vector(); - private Collection msgList; - private String keyword; + private final String keyword; /** * Creates a KeywordDatesLoader thread charged to load a list of dates @@ -550,6 +550,8 @@ public KeywordDatesLoader(String keyword) public void run() { + Collection msgList = null; + if (historyContact instanceof MetaContact) { msgList = msgHistory.findByKeyword( @@ -567,12 +569,10 @@ else if (historyContact instanceof ChatRoomWrapper) chatRoomWrapper.getChatRoom(), keyword); } - Object[] msgArray = msgList.toArray(); - Date date = null; + if (msgList != null) + for (Object o : msgList) { + Date date = null; - for (int i = 0; i < msgArray.length; i ++) { - Object o = msgArray[i]; - if (o instanceof MessageDeliveredEvent) { MessageDeliveredEvent evt = (MessageDeliveredEvent)o; date = evt.getTimestamp(); diff --git a/src/net/java/sip/communicator/impl/media/transform/TransformOutputStream.java b/src/net/java/sip/communicator/impl/media/transform/TransformOutputStream.java index bc0335fef..90060b3bb 100755 --- a/src/net/java/sip/communicator/impl/media/transform/TransformOutputStream.java +++ b/src/net/java/sip/communicator/impl/media/transform/TransformOutputStream.java @@ -83,11 +83,8 @@ public void addTarget(InetAddress remoteAddr, int remotePort) */ public boolean removeTarget(InetAddress remoteAddr, int remotePort) { - boolean ok = true; - ok = ok && this.remoteAddrs.remove(remoteAddr); - ok = ok && this.remoteAddrs.remove(new Integer(remotePort)); - - return ok; + return remoteAddrs.remove(remoteAddr) + && remotePorts.remove(new Integer(remotePort)); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java index e72ec3d30..75c05fb5e 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java @@ -52,19 +52,17 @@ protected ProtocolProviderFactoryIcqImpl(boolean isAimFactory) public AccountID installAccount( String userIDStr, Map accountProperties) { - BundleContext context - = IcqActivator.getBundleContext(); + BundleContext context = IcqActivator.getBundleContext(); if (context == null) throw new NullPointerException("The specified BundleContext was null"); if (userIDStr == null) throw new NullPointerException("The specified AccountID was null"); - - accountProperties.put(USER_ID, userIDStr); - if (accountProperties == null) throw new NullPointerException("The specified property map was null"); + accountProperties.put(USER_ID, userIDStr); + // we are installing new aim account from the wizzard, so mark it as aim if(isAimFactory) accountProperties.put(IcqAccountID.IS_AIM, "true"); diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java index 0ae15cd4d..2a4a1e343 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java @@ -74,7 +74,7 @@ public class OperationSetTypingNotificationsSipImpl private static final String COMPOSING_STATE_IDLE = "idle"; private Timer timer = new Timer(); - private Vector typingTasks = new Vector(); + private final List typingTasks = new Vector(); /** * Creates an instance of this operation set. @@ -289,7 +289,7 @@ public boolean processMessage(RequestEvent requestEvent) // process the typing info we have gathered if(state.equals(COMPOSING_STATE_ACTIVE)) { - TypingTask task = findTypigTask(from); + TypingTask task = findTypingTask(from); if(task == null) { @@ -389,16 +389,13 @@ public boolean processTimeout(TimeoutEvent timeoutEvent, Map sentMessages) return false; } - private TypingTask findTypigTask(Contact contact) + private TypingTask findTypingTask(Contact contact) { - Iterator tasksIter = typingTasks.iterator(); - while (tasksIter.hasNext()) + for (TypingTask typingTask : typingTasks) { - TypingTask typingTask = tasksIter.next(); - if(typingTask.equals(contact)) + if (typingTask.typingContact.equals(contact)) return typingTask; } - return null; } @@ -560,7 +557,7 @@ private void sendResponse(RequestEvent requestEvent, int response) public void messageReceived(MessageReceivedEvent evt) { Contact from = evt.getSourceContact(); - TypingTask task = findTypigTask(from); + TypingTask task = findTypingTask(from); if(task != null) { @@ -582,7 +579,7 @@ public void messageDeliveryFailed(MessageDeliveryFailedEvent evt) private class TypingTask extends TimerTask { - Contact typingContact = null; + public final Contact typingContact; TypingTask(Contact typingContact) { 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 2139e7ef6..5e896d3b1 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 @@ 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 contacts + = new Vector(); private ProtocolProviderServiceZeroconfImpl pps; OperationSetPersistentPresenceZeroconfImpl opSetPersPresence; @@ -587,7 +589,7 @@ public synchronized void updateRecord( JmDNS jmdns, * * @return a java.util.Iterator over all contacts */ - public Iterator contacts() + public Iterator contacts() { return contacts.iterator(); } @@ -598,6 +600,9 @@ public Iterator contacts() */ public void addContact(ContactZeroconfImpl contact) { + if (contact == null) + throw new IllegalArgumentException("contact"); + synchronized(contacts) { contacts.add(contact); @@ -617,17 +622,15 @@ public ContactZeroconfImpl getContact(String id, InetAddress ip) synchronized(contacts) { - Iterator contactsIter = contacts(); + Iterator 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 void removeContact(String id, InetAddress ip) { synchronized(contacts) { - Iterator contactsIter = contacts(); + Iterator 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))) {