From 784eaa286c7a427dee210c51e4811de455f480ba Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Wed, 15 Feb 2012 20:35:21 +0000 Subject: [PATCH] Fixes a NullPointerException in CallPeerMediaHandler#close(). --- .../protocol/media/CallPeerMediaHandler.java | 70 ++++++++++++++++--- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java b/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java index f653ceb08..d19c4d9b8 100644 --- a/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java +++ b/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java @@ -32,6 +32,7 @@ * or CallPeerJabberImpl * * @author Emil Ivov + * @author Lyubomir Marinov */ public abstract class CallPeerMediaHandler< T extends MediaAwareCallPeer> @@ -328,14 +329,7 @@ public void videoUpdate( * The PropertyChangeListener which listens to changes in the * values of the properties of the Call of {@link #peer}. */ - private final PropertyChangeListener callPropertyChangeListener - = new PropertyChangeListener() - { - public void propertyChange(PropertyChangeEvent event) - { - callPropertyChange(event); - } - }; + private final CallPropertyChangeListener callPropertyChangeListener; /** * Creates a new handler that will be managing media streams for @@ -351,7 +345,19 @@ public CallPeerMediaHandler(T peer, this.peer = peer; this.srtpListener = srtpListener; - peer.getCall().addPropertyChangeListener(callPropertyChangeListener); + /* + * Listener to the call of peer in order to track the user's choice with + * respect to the default audio device. + */ + MediaAwareCall call = this.peer.getCall(); + + if (call == null) + callPropertyChangeListener = null; + else + { + callPropertyChangeListener = new CallPropertyChangeListener(call); + call.addPropertyChangeListener(callPropertyChangeListener); + } } /** @@ -420,7 +426,9 @@ public synchronized void close() locallyOnHold = false; - peer.getCall().removePropertyChangeListener(callPropertyChangeListener); + if (callPropertyChangeListener != null) + callPropertyChangeListener.call.removePropertyChangeListener( + callPropertyChangeListener); } /** @@ -1825,4 +1833,46 @@ protected abstract void throwOperationFailedException( String message, * management */ protected abstract TransportManager getTransportManager(); + + /** + * Represents the PropertyChangeListener which listens to changes + * in the values of the properties of the Call of {@link #peer}. + * Remembers the Call it has been added to because peer + * does not have a call anymore at the time {@link #close()} is + * called. + */ + private class CallPropertyChangeListener + implements PropertyChangeListener + { + /** + * The Call this PropertyChangeListener will be or is + * already added to. + */ + public final MediaAwareCall call; + + /** + * Initializes a new CallPropertyChangeListener which is to be + * added to a specific Call. + * + * @param call the Call the new instance is to be added to + */ + public CallPropertyChangeListener(MediaAwareCall call) + { + this.call = call; + } + + /** + * Notifies this instance that the value of a specific property of + * {@link #call} has changed from a specific old value to a specific + * new value. + * + * @param event a PropertyChangeEvent which specifies the name + * of the property which had its value changed and the old and new + * values + */ + public void propertyChange(PropertyChangeEvent event) + { + callPropertyChange(event); + } + } }