Program: 49765
Project: 49765
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) {
  }
  if (timeout > 0) {
    selector.select(timeout);
  }
 else {
    selector.selectNow();
  }
  Set<SelectionKey> keys=selector.selectedKeys();
  outer:   for (Iterator<SelectionKey> iter=keys.iterator(); iter.hasNext(); ) {
    SelectionKey selectionKey=iter.next();
    iter.remove();
    try {
      int ops=selectionKey.readyOps();
      Connection keyConnection=(Connection)selectionKey.attachment();
      if (keyConnection != null) {
        if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
          try {
            while (true) {
              Object object=keyConnection.tcp.readObject(keyConnection);
              if (object == null)               break;
              if (DEBUG) {
                String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
                if (!(object instanceof FrameworkMessage)) {
                  debug("String_Node_Str",keyConnection + "String_Node_Str" + objectString);
                }
 else                 if (TRACE) {
                  trace("String_Node_Str",keyConnection + "String_Node_Str" + objectString);
                }
              }
              keyConnection.notifyReceived(object);
            }
          }
 catch (          IOException ex) {
            if (TRACE) {
              trace("String_Node_Str","String_Node_Str" + keyConnection,ex);
            }
 else             if (DEBUG) {
              debug("String_Node_Str",keyConnection + "String_Node_Str" + ex.getMessage());
            }
            keyConnection.close();
          }
catch (          SerializationException ex) {
            if (ERROR)             error("String_Node_Str","String_Node_Str" + keyConnection,ex);
            keyConnection.close();
          }
        }
        if ((ops & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
          try {
            keyConnection.tcp.writeOperation();
          }
 catch (          IOException ex) {
            if (TRACE) {
              trace("String_Node_Str","String_Node_Str" + keyConnection,ex);
            }
 else             if (DEBUG) {
              debug("String_Node_Str",keyConnection + "String_Node_Str" + ex.getMessage());
            }
            keyConnection.close();
          }
        }
        continue;
      }
      if ((ops & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT) {
        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) {
        IOException ioEx=new IOException("String_Node_Str");
        ioEx.initCause(ex);
        throw ioEx;
      }
      if (fromAddress == null)       continue;
      Connection[] connections=this.connections;
      Connection fromConnection=null;
      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 (      SerializationException ex) {
        if (WARN) {
          Connection errorConnection=null;
          for (int i=0, n=connections.length; i < n; i++) {
            Connection connection=connections[i];
            if (fromAddress.equals(connection.udpRemoteAddress)) {
              errorConnection=connection;
              break;
            }
          }
          if (errorConnection != null) {
            if (ERROR)             error("String_Node_Str","String_Node_Str" + errorConnection,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) {
          udp.datagramChannel.send(udp.writeBuffer,fromAddress);
          if (DEBUG)           debug("String_Node_Str","String_Node_Str" + fromAddress);
          continue;
        }
      }
      if (fromConnection != null) {
        if (DEBUG) {
          String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
          if (object instanceof KeepAlive) {
            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) {
    }
  }
}

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) {
  }
  if (timeout > 0) {
    selector.select(timeout);
  }
 else {
    selector.selectNow();
  }
  Set<SelectionKey> keys=selector.selectedKeys();
  outer:   for (Iterator<SelectionKey> iter=keys.iterator(); iter.hasNext(); ) {
    SelectionKey selectionKey=iter.next();
    iter.remove();
    try {
      int ops=selectionKey.readyOps();
      Connection keyConnection=(Connection)selectionKey.attachment();
      if (keyConnection != null) {
        if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
          try {
            while (true) {
              Object object=keyConnection.tcp.readObject(keyConnection);
              if (object == null)               break;
              if (DEBUG) {
                String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
                if (!(object instanceof FrameworkMessage)) {
                  debug("String_Node_Str",keyConnection + "String_Node_Str" + objectString);
                }
 else                 if (TRACE) {
                  trace("String_Node_Str",keyConnection + "String_Node_Str" + objectString);
                }
              }
              keyConnection.notifyReceived(object);
            }
          }
 catch (          IOException ex) {
            if (TRACE) {
              trace("String_Node_Str","String_Node_Str" + keyConnection,ex);
            }
 else             if (DEBUG) {
              debug("String_Node_Str",keyConnection + "String_Node_Str" + ex.getMessage());
            }
            keyConnection.close();
          }
catch (          SerializationException ex) {
            if (ERROR)             error("String_Node_Str","String_Node_Str" + keyConnection,ex);
            keyConnection.close();
          }
        }
        if ((ops & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
          try {
            keyConnection.tcp.writeOperation();
          }
 catch (          IOException ex) {
            if (TRACE) {
              trace("String_Node_Str","String_Node_Str" + keyConnection,ex);
            }
 else             if (DEBUG) {
              debug("String_Node_Str",keyConnection + "String_Node_Str" + ex.getMessage());
            }
            keyConnection.close();
          }
        }
        continue;
      }
      if ((ops & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT) {
        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) {
        IOException ioEx=new IOException("String_Node_Str");
        ioEx.initCause(ex);
        throw ioEx;
      }
      if (fromAddress == null)       continue;
      Connection[] connections=this.connections;
      Connection fromConnection=null;
      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 (      SerializationException ex) {
        if (WARN) {
          Connection errorConnection=null;
          for (int i=0, n=connections.length; i < n; i++) {
            Connection connection=connections[i];
            if (fromAddress.equals(connection.udpRemoteAddress)) {
              errorConnection=connection;
              break;
            }
          }
          if (errorConnection != null) {
            if (ERROR)             error("String_Node_Str","String_Node_Str" + errorConnection,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) {
          udp.datagramChannel.send(emptyBuffer,fromAddress);
          if (DEBUG)           debug("String_Node_Str","String_Node_Str" + fromAddress);
          continue;
        }
      }
      if (fromConnection != null) {
        if (DEBUG) {
          String objectString=object == null ? "String_Node_Str" : object.getClass().getSimpleName();
          if (object instanceof KeepAlive) {
            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) {
    }
  }
}