Buggy code:
private static final String rightBrace = "}" ; private static final byte NULL_VALUE = ( ( byte ) ( 255 ) ) ; private static final String SYNTAX_ERR = "42X01" ; private static final int MGRLVL_3 = 3 ; private static final int MGRLVL_4 = 4 ; private static final int MGRLVL_5 = 5 ; private static final int MGRLVL_6 = 6 ; private static final int MGRLVL_7 = 7 ; private static final int COMMIT = 1 ; private static final int ROLLBACK = 2 ; protected CcsidManager ccsidManager = new EbcdicCcsidManager ( ) ; private int correlationID ; private InputStream sockis ; private OutputStream sockos ; private DDMReader reader ; private DDMWriter writer ; private DRDAXAProtocol xaProto ; private static int [ ] ACCRDB_REQUIRED = new int [ ] { CodePoint . RDBACCCL , CodePoint . CRRTKN , CodePoint . PRDID , CodePoint . TYPDEFNAM , CodePoint . TYPDEFOVR } ; private static int MAX_REQUIRED_LEN = 5 ; private int currentRequiredLength = 0 ; private int [ ] required = new int [ DRDAConnThread . MAX_REQUIRED_LEN ] ; private NetworkServerControlImpl server ; private Session session ; private long timeSlice ; private Object timeSliceSync = new Object ( ) ; private boolean logConnections ; private boolean sendWarningsOnCNTQRY = false ; private Object logConnectionsSync = new Object ( ) ; private boolean close ; private Object closeSync = new Object ( ) ; private static HeaderPrintWriter logStream ; private AppRequester appRequester ; private Database database ; private int sqlamLevel ; private byte diagnosticLevel = ( ( byte ) ( 240 ) ) ; private Vector unknownManagers ; private Vector knownManagers ; private Vector errorManagers ; private Vector errorManagersLevel ; private SQLException databaseAccessException ; private Pkgnamcsn prevPkgnamcsn = null ; private DRDAString rdbnam = new DRDAString ( ccsidManager ) ; private DRDAString rdbcolid = new DRDAString ( ccsidManager ) ; private DRDAString pkgid = new DRDAString ( ccsidManager ) ; private DRDAString pkgcnstkn = new DRDAString ( ccsidManager ) ; private int pkgsn ; private static final String TIMEOUT_STATEMENT = "SET<seq2seq4repair_space>STATEMENT_TIMEOUT<seq2seq4repair_space>" ; private int pendingStatementTimeout ; private static DecryptionManager decryptionManager ; private byte [ ] myPublicKey ; private byte [ ] myTargetSeed ; private static final byte [ ] eod00000 = new byte [ ] { '0' , '0' , '0' , '0' , '0' } ; private static final byte [ ] eod02000 = new byte [ ] { '0' , '2' , '0' , '0' , '0' } ; private static final byte [ ] nullSQLState = new byte [ ] { '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' } ; private static final byte [ ] errD4_D6 = new byte [ ] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; private static final byte [ ] warn0_warnA = new byte [ ] { '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' , '<seq2seq4repair_space>' } ; private static final String AUTHENTICATION_PROVIDER_BUILTIN_CLASS = "org.apache.derby.impl.jdbc.authentication.BasicAuthenticationServiceImpl" ; private static final String AUTHENTICATION_PROVIDER_NONE_CLASS = "org.apache.derby.impl.jdbc.authentication.NoneAuthenticationServiceImpl" ; private static final DRDAProtocolExceptionInfo dummy = new DRDAProtocolExceptionInfo ( 0 , 0 , 0 , false ) ; DRDAConnThread ( Session session , NetworkServerControlImpl server , long timeSlice , boolean logConnections ) { } public void run ( ) { if ( SanityManager . DEBUG ) trace ( "Starting<seq2seq4repair_space>new<seq2seq4repair_space>connection<seq2seq4repair_space>thread" ) ; Session prevSession ; while ( ! ( closed ( ) ) ) { prevSession = session ; session = server . getNextSession ( session ) ; if ( ( session ) == null ) close ( ) ; if ( closed ( ) ) break ; if ( ( session ) != prevSession ) { initializeForSession ( ) ; } try { long timeStart = System . currentTimeMillis ( ) ; switch ( session . state ) { case Session . INIT : sessionInitialState ( ) ; if ( ( session ) == null ) break ; case Session . ATTEXC : long currentTimeSlice ; do { processCommands ( ) ; currentTimeSlice = getTimeSlice ( ) ; } while ( ( currentTimeSlice == 0 ) || ( ( ( System . currentTimeMillis ( ) ) - timeStart ) < currentTimeSlice ) ) ; break ; default : agentError ( ( "Session<seq2seq4repair_space>in<seq2seq4repair_space>invalid<seq2seq4repair_space>state:" + ( session . state ) ) ) ; } } catch ( Exception e ) { if ( ( e instanceof DRDAProtocolException ) && ( ( ( DRDAProtocolException ) ( e ) ) . isDisconnectException ( ) ) ) { closeSession ( ) ; } else { handleException ( e ) ; } } } if ( SanityManager . DEBUG ) trace ( "Ending<seq2seq4repair_space>connection<seq2seq4repair_space>thread" ) ; <START_BUG> server . getThreadList ( ) . removeElement ( this ) ; <END_BUG> } protected InputStream getInputStream ( ) { } protected OutputStream getOutputStream ( ) { } protected DDMReader getReader ( ) { } protected DDMWriter getWriter ( ) { } protected int getCorrelationID ( ) { } protected Session getSession ( ) { } protected Database getDatabase ( ) { } protected NetworkServerControlImpl getServer ( ) { } protected byte [ ] getCrrtkn ( ) { } protected String getDbName ( ) { } protected void close ( ) { } protected void setLogConnections ( boolean value ) { } protected void setTimeSlice ( long value ) { } protected void markCommunicationsFailure ( String arg1 , String arg2 , String arg3 , String arg4 ) throws DRDAProtocolException { } protected void throwSyntaxrm ( int errcd , int cpArg ) throws DRDAProtocolException { } protected void agentError ( String msg ) throws DRDAProtocolException { } protected void missingCodePoint ( int codePoint ) throws DRDAProtocolException { } protected static void println2Log ( String dbname , String drdaID , String msg ) { } protected void writeRDBNAM ( String rdbnam ) throws DRDAProtocolException { } private void initialize ( ) { } private void initializeForSession ( ) { } private void sessionInitialState ( ) throws Exception { } private void cleanUpAndCloseResultSet ( DRDAStatement stmt , SQLException sqle , int writerMark ) throws DRDAProtocolException { } private void processCommands ( ) throws DRDAProtocolException { }

Fix:
server . removeThread ( this ) ;