Program: 107657
Project: 107657
Buggy source:
/** 
 * Notifies this <tt>MediaStream</tt> that the <tt>MediaDevice</tt> (and respectively the <tt>MediaDeviceSession</tt> with it) which this instance uses for capture and playback of media has been changed. Makes sure that the <tt>VideoListener</tt>s of this instance get <tt>VideoEvent</tt>s for the new/current <tt>VideoMediaDeviceSession</tt> and not for the old one.
 * @param oldValue the <tt>MediaDeviceSession</tt> with the<tt>MediaDevice</tt> this instance used work with
 * @param newValue the <tt>MediaDeviceSession</tt> with the<tt>MediaDevice</tt> this instance is to work with
 * @see MediaStreamImpl#deviceSessionChanged(MediaDeviceSession,MediaDeviceSession)
 */
@Override protected void deviceSessionChanged(MediaDeviceSession oldValue,MediaDeviceSession newValue){
  super.deviceSessionChanged(oldValue,newValue);
  if (oldValue instanceof VideoMediaDeviceSession) {
    VideoMediaDeviceSession oldVideoMediaDeviceSession=(VideoMediaDeviceSession)oldValue;
    if (deviceSessionVideoListener != null)     oldVideoMediaDeviceSession.removeVideoListener(deviceSessionVideoListener);
    oldVideoMediaDeviceSession.setKeyFrameControl(null);
  }
  if (newValue instanceof VideoMediaDeviceSession) {
    VideoMediaDeviceSession newVideoMediaDeviceSession=(VideoMediaDeviceSession)newValue;
    if (deviceSessionVideoListener == null) {
      deviceSessionVideoListener=new VideoListener(){
        /** 
 * {@inheritDoc}Notifies that a visual <tt>Component</tt> depicting video was reported added by the provider this listener is added to.
 */
        public void videoAdded(        VideoEvent e){
          if (fireVideoEvent(e.getType(),e.getVisualComponent(),e.getOrigin(),true))           e.consume();
        }
        /** 
 * {@inheritDoc}Notifies that a visual <tt>Component</tt> depicting video was reported removed by the provider this listener is added to.
 */
        public void videoRemoved(        VideoEvent e){
          videoAdded(e);
        }
        /** 
 * {@inheritDoc}Notifies that a visual <tt>Component</tt> depicting video was reported updated by the provider this listener is added to.
 */
        public void videoUpdate(        VideoEvent e){
          fireVideoEvent(e,true);
        }
      }
;
    }
    newVideoMediaDeviceSession.addVideoListener(deviceSessionVideoListener);
    newVideoMediaDeviceSession.setOutputSize(outputSize);
    AbstractRTPConnector rtpConnector=getRTPConnector();
    if (rtpConnector != null)     newVideoMediaDeviceSession.setConnector(rtpConnector);
    newVideoMediaDeviceSession.setRtcpFeedbackPLI(usePLI);
    newVideoMediaDeviceSession.setKeyFrameControl(getKeyFrameControl());
  }
}

Fixed version (ground truth):
/** 
 * Notifies this <tt>MediaStream</tt> that the <tt>MediaDevice</tt> (and respectively the <tt>MediaDeviceSession</tt> with it) which this instance uses for capture and playback of media has been changed. Makes sure that the <tt>VideoListener</tt>s of this instance get <tt>VideoEvent</tt>s for the new/current <tt>VideoMediaDeviceSession</tt> and not for the old one. Note: this overloaded method gets executed in the <tt>MediaStreamImpl</tt> constructor. As a consequence we cannot assume proper initialization of the fields specific to <tt>VideoMediaStreamImpl</tt>.
 * @param oldValue the <tt>MediaDeviceSession</tt> with the<tt>MediaDevice</tt> this instance used work with
 * @param newValue the <tt>MediaDeviceSession</tt> with the<tt>MediaDevice</tt> this instance is to work with
 * @see MediaStreamImpl#deviceSessionChanged(MediaDeviceSession,MediaDeviceSession)
 */
@Override protected void deviceSessionChanged(MediaDeviceSession oldValue,MediaDeviceSession newValue){
  super.deviceSessionChanged(oldValue,newValue);
  if (oldValue instanceof VideoMediaDeviceSession) {
    VideoMediaDeviceSession oldVideoMediaDeviceSession=(VideoMediaDeviceSession)oldValue;
    if (deviceSessionVideoListener != null)     oldVideoMediaDeviceSession.removeVideoListener(deviceSessionVideoListener);
    oldVideoMediaDeviceSession.setKeyFrameControl(null);
  }
  if (newValue instanceof VideoMediaDeviceSession) {
    VideoMediaDeviceSession newVideoMediaDeviceSession=(VideoMediaDeviceSession)newValue;
    if (deviceSessionVideoListener == null) {
      deviceSessionVideoListener=new VideoListener(){
        /** 
 * {@inheritDoc}Notifies that a visual <tt>Component</tt> depicting video was reported added by the provider this listener is added to.
 */
        public void videoAdded(        VideoEvent e){
          if (fireVideoEvent(e.getType(),e.getVisualComponent(),e.getOrigin(),true))           e.consume();
        }
        /** 
 * {@inheritDoc}Notifies that a visual <tt>Component</tt> depicting video was reported removed by the provider this listener is added to.
 */
        public void videoRemoved(        VideoEvent e){
          videoAdded(e);
        }
        /** 
 * {@inheritDoc}Notifies that a visual <tt>Component</tt> depicting video was reported updated by the provider this listener is added to.
 */
        public void videoUpdate(        VideoEvent e){
          fireVideoEvent(e,true);
        }
      }
;
    }
    newVideoMediaDeviceSession.addVideoListener(deviceSessionVideoListener);
    newVideoMediaDeviceSession.setOutputSize(outputSize);
    AbstractRTPConnector rtpConnector=getRTPConnector();
    if (rtpConnector != null)     newVideoMediaDeviceSession.setConnector(rtpConnector);
    newVideoMediaDeviceSession.setRtcpFeedbackPLI(USE_PLI);
    newVideoMediaDeviceSession.setKeyFrameControl(getKeyFrameControl());
  }
}