Program: 49756
Project: 49756
Buggy source:
/** 
 * Accepts any new connections and reads or writes any pending data for the current connections.
 * @param timeout Wait for up to the specified milliseconds for a connection to be ready to process. May be zero to returnimmediately if there are no connections to process. 
 */
public void update(int timeout) throws IOException {
  updateThread=Thread.currentThread();
synchronized (updateLock) {
  }
  long startTime=System.currentTimeMillis();
  int select=0;
  if (timeout > 0) {
    select=selector.select(timeout);
  }
 else {
    select=selector.selectNow();
  }
  System.out.println(select);
  if (select == 0) {
    long elapsedTime=System.currentTimeMillis() - startTime;
    try {
      if (elapsedTime < 25)       Thread.sleep(25 - elapsedTime);
    }
 catch (    InterruptedException ex) {
    }
  }
 else {
    Set<SelectionKey> keys=selector.selectedKeys();
synchronized (keys) {
      UdpConnection udp=this.udp;
      outer:       for (Iterator<SelectionKey> iter=keys.iterator(); iter.hasNext(); ) {
        SelectionKey selectionKey=iter.next();
        iter.remove();
        try {
          int ops=selectionKey.readyOps();
          Connection fromConnection=(Connection)selectionKey.attachment();
          if (fromConnection != null) {
            if (udp != null && fromConnection.udpRemoteAddress == null) {
              fromConnection.close();
              continue;
            }
            if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
              try {
                while (true) {
                  Object object=fromConnection.tcp.readObject(fromConnection);
                  if (object == null)                   break;
                  if (DEBUG) {
                    String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
                    if (!(object instanceof FrameworkMessage)) {
                      debug("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
                    }
 else                     if (TRACE) {
                      trace("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
                    }
                  }
                  fromConnection.notifyReceived(object);
                }
              }
 catch (              IOException ex) {
                if (TRACE) {
                  trace("String_Node_Str","String_Node_Str" + fromConnection,ex);
                }
 else                 if (DEBUG) {
                  debug("String_Node_Str",fromConnection + "String_Node_Str" + ex.getMessage());
                }
                fromConnection.close();
              }
catch (              KryoNetException ex) {
                if (ERROR)                 error("String_Node_Str","String_Node_Str" + fromConnection,ex);
                fromConnection.close();
              }
            }
            if ((ops & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
              try {
                fromConnection.tcp.writeOperation();
              }
 catch (              IOException ex) {
                if (TRACE) {
                  trace("String_Node_Str","String_Node_Str" + fromConnection,ex);
                }
 else                 if (DEBUG) {
                  debug("String_Node_Str",fromConnection + "String_Node_Str" + ex.getMessage());
                }
                fromConnection.close();
              }
            }
            continue;
          }
          if ((ops & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT) {
            ServerSocketChannel serverChannel=this.serverChannel;
            if (serverChannel == null)             continue;
            try {
              SocketChannel socketChannel=serverChannel.accept();
              if (socketChannel != null)               acceptOperation(socketChannel);
            }
 catch (            IOException ex) {
              if (DEBUG)               debug("String_Node_Str","String_Node_Str",ex);
            }
            continue;
          }
          if (udp == null)           continue;
          InetSocketAddress fromAddress;
          try {
            fromAddress=udp.readFromAddress();
          }
 catch (          IOException ex) {
            if (WARN)             warn("String_Node_Str","String_Node_Str",ex);
            continue;
          }
          if (fromAddress == null)           continue;
          Connection[] connections=this.connections;
          for (int i=0, n=connections.length; i < n; i++) {
            Connection connection=connections[i];
            if (fromAddress.equals(connection.udpRemoteAddress)) {
              fromConnection=connection;
              break;
            }
          }
          Object object;
          try {
            object=udp.readObject(fromConnection);
          }
 catch (          KryoNetException ex) {
            if (WARN) {
              if (fromConnection != null) {
                if (ERROR)                 error("String_Node_Str","String_Node_Str" + fromConnection,ex);
              }
 else               warn("String_Node_Str","String_Node_Str" + fromAddress,ex);
            }
            continue;
          }
          if (object instanceof FrameworkMessage) {
            if (object instanceof RegisterUDP) {
              int fromConnectionID=((RegisterUDP)object).connectionID;
              Connection connection=pendingConnections.remove(fromConnectionID);
              if (connection != null) {
                if (connection.udpRemoteAddress != null)                 continue outer;
                connection.udpRemoteAddress=fromAddress;
                addConnection(connection);
                connection.sendTCP(new RegisterUDP());
                if (DEBUG)                 debug("String_Node_Str","String_Node_Str" + udp.datagramChannel.socket().getLocalPort() + "String_Node_Str"+ fromAddress);
                connection.notifyConnected();
                continue;
              }
              if (DEBUG)               debug("String_Node_Str","String_Node_Str" + fromConnectionID);
              continue;
            }
            if (object instanceof DiscoverHost) {
              try {
                udp.datagramChannel.send(emptyBuffer,fromAddress);
                if (DEBUG)                 debug("String_Node_Str","String_Node_Str" + fromAddress);
              }
 catch (              IOException ex) {
                if (WARN)                 warn("String_Node_Str","String_Node_Str" + fromAddress,ex);
              }
              continue;
            }
          }
          if (fromConnection != null) {
            if (DEBUG) {
              String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
              if (object instanceof FrameworkMessage) {
                if (TRACE)                 trace("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
              }
 else               debug("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
            }
            fromConnection.notifyReceived(object);
            continue;
          }
          if (DEBUG)           debug("String_Node_Str","String_Node_Str" + fromAddress);
        }
 catch (        CancelledKeyException ignored) {
        }
      }
    }
  }
  long time=System.currentTimeMillis();
  Connection[] connections=this.connections;
  for (int i=0, n=connections.length; i < n; i++) {
    Connection connection=connections[i];
    if (connection.tcp.isTimedOut(time)) {
      if (DEBUG)       debug("String_Node_Str",connection + "String_Node_Str");
      connection.close();
    }
 else {
      if (connection.tcp.needsKeepAlive(time))       connection.sendTCP(FrameworkMessage.keepAlive);
    }
    if (connection.isIdle())     connection.notifyIdle();
  }
}

Fixed version (ground truth):
/** 
 * Accepts any new connections and reads or writes any pending data for the current connections.
 * @param timeout Wait for up to the specified milliseconds for a connection to be ready to process. May be zero to returnimmediately if there are no connections to process. 
 */
public void update(int timeout) throws IOException {
  updateThread=Thread.currentThread();
synchronized (updateLock) {
  }
  long startTime=System.currentTimeMillis();
  int select=0;
  if (timeout > 0) {
    select=selector.select(timeout);
  }
 else {
    select=selector.selectNow();
  }
  System.out.println(select);
  if (select == 0) {
    long elapsedTime=System.currentTimeMillis() - startTime;
    try {
      if (elapsedTime < 25)       Thread.sleep(25 - elapsedTime);
    }
 catch (    InterruptedException ex) {
    }
  }
 else {
    Set<SelectionKey> keys=selector.selectedKeys();
synchronized (keys) {
      UdpConnection udp=this.udp;
      outer:       for (Iterator<SelectionKey> iter=keys.iterator(); iter.hasNext(); ) {
        SelectionKey selectionKey=iter.next();
        iter.remove();
        Connection fromConnection=(Connection)selectionKey.attachment();
        try {
          int ops=selectionKey.readyOps();
          if (fromConnection != null) {
            if (udp != null && fromConnection.udpRemoteAddress == null) {
              fromConnection.close();
              continue;
            }
            if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
              try {
                while (true) {
                  Object object=fromConnection.tcp.readObject(fromConnection);
                  if (object == null)                   break;
                  if (DEBUG) {
                    String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
                    if (!(object instanceof FrameworkMessage)) {
                      debug("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
                    }
 else                     if (TRACE) {
                      trace("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
                    }
                  }
                  fromConnection.notifyReceived(object);
                }
              }
 catch (              IOException ex) {
                if (TRACE) {
                  trace("String_Node_Str","String_Node_Str" + fromConnection,ex);
                }
 else                 if (DEBUG) {
                  debug("String_Node_Str",fromConnection + "String_Node_Str" + ex.getMessage());
                }
                fromConnection.close();
              }
catch (              KryoNetException ex) {
                if (ERROR)                 error("String_Node_Str","String_Node_Str" + fromConnection,ex);
                fromConnection.close();
              }
            }
            if ((ops & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
              try {
                fromConnection.tcp.writeOperation();
              }
 catch (              IOException ex) {
                if (TRACE) {
                  trace("String_Node_Str","String_Node_Str" + fromConnection,ex);
                }
 else                 if (DEBUG) {
                  debug("String_Node_Str",fromConnection + "String_Node_Str" + ex.getMessage());
                }
                fromConnection.close();
              }
            }
            continue;
          }
          if ((ops & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT) {
            ServerSocketChannel serverChannel=this.serverChannel;
            if (serverChannel == null)             continue;
            try {
              SocketChannel socketChannel=serverChannel.accept();
              if (socketChannel != null)               acceptOperation(socketChannel);
            }
 catch (            IOException ex) {
              if (DEBUG)               debug("String_Node_Str","String_Node_Str",ex);
            }
            continue;
          }
          if (udp == null) {
            selectionKey.channel().close();
            continue;
          }
          InetSocketAddress fromAddress;
          try {
            fromAddress=udp.readFromAddress();
          }
 catch (          IOException ex) {
            if (WARN)             warn("String_Node_Str","String_Node_Str",ex);
            continue;
          }
          if (fromAddress == null)           continue;
          Connection[] connections=this.connections;
          for (int i=0, n=connections.length; i < n; i++) {
            Connection connection=connections[i];
            if (fromAddress.equals(connection.udpRemoteAddress)) {
              fromConnection=connection;
              break;
            }
          }
          Object object;
          try {
            object=udp.readObject(fromConnection);
          }
 catch (          KryoNetException ex) {
            if (WARN) {
              if (fromConnection != null) {
                if (ERROR)                 error("String_Node_Str","String_Node_Str" + fromConnection,ex);
              }
 else               warn("String_Node_Str","String_Node_Str" + fromAddress,ex);
            }
            continue;
          }
          if (object instanceof FrameworkMessage) {
            if (object instanceof RegisterUDP) {
              int fromConnectionID=((RegisterUDP)object).connectionID;
              Connection connection=pendingConnections.remove(fromConnectionID);
              if (connection != null) {
                if (connection.udpRemoteAddress != null)                 continue outer;
                connection.udpRemoteAddress=fromAddress;
                addConnection(connection);
                connection.sendTCP(new RegisterUDP());
                if (DEBUG)                 debug("String_Node_Str","String_Node_Str" + udp.datagramChannel.socket().getLocalPort() + "String_Node_Str"+ fromAddress);
                connection.notifyConnected();
                continue;
              }
              if (DEBUG)               debug("String_Node_Str","String_Node_Str" + fromConnectionID);
              continue;
            }
            if (object instanceof DiscoverHost) {
              try {
                udp.datagramChannel.send(emptyBuffer,fromAddress);
                if (DEBUG)                 debug("String_Node_Str","String_Node_Str" + fromAddress);
              }
 catch (              IOException ex) {
                if (WARN)                 warn("String_Node_Str","String_Node_Str" + fromAddress,ex);
              }
              continue;
            }
          }
          if (fromConnection != null) {
            if (DEBUG) {
              String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
              if (object instanceof FrameworkMessage) {
                if (TRACE)                 trace("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
              }
 else               debug("String_Node_Str",fromConnection + "String_Node_Str" + objectString);
            }
            fromConnection.notifyReceived(object);
            continue;
          }
          if (DEBUG)           debug("String_Node_Str","String_Node_Str" + fromAddress);
        }
 catch (        CancelledKeyException ex) {
          if (fromConnection != null)           fromConnection.close();
 else           selectionKey.channel().close();
        }
      }
    }
  }
  long time=System.currentTimeMillis();
  Connection[] connections=this.connections;
  for (int i=0, n=connections.length; i < n; i++) {
    Connection connection=connections[i];
    if (connection.tcp.isTimedOut(time)) {
      if (DEBUG)       debug("String_Node_Str",connection + "String_Node_Str");
      connection.close();
    }
 else {
      if (connection.tcp.needsKeepAlive(time))       connection.sendTCP(FrameworkMessage.keepAlive);
    }
    if (connection.isIdle())     connection.notifyIdle();
  }
}