Buggy code:
public class MessageServer extends Server { private static Logger logger = LoggerFactory . get ( MessageServer . class ) ; public static final String MESSAGE_TYPE_JSON = "json" ; public static final String MESSAGE_TYPE_AMF3 = "amf3" ; public static final String MESSAGE_TYPE_ZJSON = "zjson" ; static final int DEFAULT_PORT = 3001 ; static final int DEFAULT_IDLE_TIME = 60 * 10 ; static final int DEFAULT_MAX_SESSION_COUNT = 8000 ; static final int DEFAULT_MAX_CHANNEL_COUNT = 1000 ; ServerBootstrap nettyServer ; EventLoopGroup bossGroup ; EventLoopGroup workerGroup ; ChannelInitializer < SocketChannel > channelInitializer ; int port ; int idleTime ; String messageType ; int sessionTimeout ; int maxSessionCount ; int maxChannelCount ; NetworkTrafficStat networkTrafficStat ; Map < String , ServiceStub > serviceMap ; Map < Integer , Session > sessionMap ; Map < String , Session > principalMap ; AtomicInteger sessionId ; Map < String , Channel > channelMap ; SessionLifecycleListener sessionLifecycleListener ; Method sessionCreatedMethod ; Method sessionDisconnectedMethod ; ServiceFilter serviceFilter ; public MessageServer ( ) { } public int getPort ( ) { } public void setPort ( int port ) { } public int getIdleTime ( ) { } public void setIdleTime ( int idleTime ) { } public String getMessageType ( ) { } public void setMessageType ( String messageType ) { } public int getMaxSessionCount ( ) { } public void setMaxSessionCount ( int maxSessionCount ) { } public int getMaxChannelCount ( ) { } public void setMaxChannelCount ( int maxChannelCount ) { } public List < String > getServiceNames ( ) { } List < ServiceStub > getServices ( ) { } public List < Session > getSessions ( ) { } public int getSessionCount ( ) { } public List < Channel > getChannels ( ) { } public long getInBoundBytes ( ) { } public long getOutBoundBytes ( ) { } private void startSessionChecker ( ) { } private void checkPrincipal ( long currentTime , Session session ) { } public void setSessionLifecycleListener ( SessionLifecycleListener l ) { } public SessionLifecycleListener getSessionLifecycleListener ( ) { } public void setServiceFilter ( ServiceFilter sf ) { } public ServiceFilter getServiceFilter ( ) { } class MessageServerChannelInitializer extends ChannelInitializer < SocketChannel > { @ Override protected void initChannel ( SocketChannel ch ) throws Exception { } } protected void initNettyServer ( ) { } private boolean checkParameterTypes ( Method m ) { } public void registerService ( Object instance ) { } private ServiceStub checkMessage ( Session session , RequestMessage message ) { } private Object [ ] getParameters ( Context context , Session session , ServiceStub stub , RequestMessage message ) { } private void invokeService ( Session session , ServiceStub stub , RequestMessage message ) { } static class MessageDispatcherCallback extends DispatcherCallbackAdapter { public Session session ; public RequestMessage requestMessage ; public ServiceFilter serviceFilter ; @ Override public void before ( Object instance , Method method , Object [ ] args ) throws Exception { } @ Override public void end ( Object instance , Method method , Object [ ] args , Object ret , Throwable e ) { } } void receiveMessage ( Session session , RequestMessage message ) { } void sessionIdle ( Session session ) { } void sessionCreated ( Session session ) { } private void sessionCreated0 ( Session session ) { } void sessionDisconnected ( Session session ) { } private void sessionDisconnected0 ( Session session ) { if ( ( session . principal ) == null ) { MessageServer . logger . debug ( ( ( ( ( ( "bad<seq2seq4repair_space>session<seq2seq4repair_space>disconnected:" + ( session . id ) ) + "//" ) + ( session . remoteHostAddress ) ) + ":" ) + ( session . remotePort ) ) ) ; sessionMap . remove ( session . id ) ; return ; } if ( MessageServer . logger . isDebugEnabled ( ) ) { MessageServer . logger . debug ( ( ( ( ( ( ( ( "session<seq2seq4repair_space>disconnected:" + ( session . id ) ) + "//" ) + ( session . principal ) ) + "//" ) + ( session . remoteHostAddress ) ) + ":" ) + ( session . remotePort ) ) ) ; } sessionMap . remove ( session . id ) ; if ( ( session . principal ) != null ) { principalMap . remove ( session . principal ) ; } session . channels . forEach ( ( cname ) -> { Channel cc = getChannel ( cname ) ; if ( cc != null ) { <START_BUG> session . leaveChannel ( cc ) ; <END_BUG> } } ) ; if ( ( sessionLifecycleListener ) != null ) { dispatcher . invokeInPool ( session . principal , sessionLifecycleListener , sessionDisconnectedMethod , EMPTY_CALLBACK , session ) ; } } public Session getSessionByPrincipal ( String principal ) { } public Session getSessionById ( int id ) { } public void setPrincipal ( Session s , String principal , String userAgent ) { } private void setPrincipal0 ( Session session , String principal , String userAgent ) { } public void broadcast ( String serviceId , Object payload ) { } public Channel createChannel ( String id ) { } public Channel getChannel ( String id ) { } public int getChannelCount ( ) { } void removeChannelInternal ( String id ) { } @ Override public void init ( ) throws Exception { } @ Override public void start ( ) throws Exception { } @ Override public void stop ( ) throws Exception { } @ Override public String info ( ) { } }

Fix:
cc . removeSession ( session ) ;