Program: 5095
Project: 5095
Buggy source:
/** 
 * Handles core Gnutella request/reply protocol.
 * @requires this is in the CONNECTED state andthe manager to this has been set via setManager
 * @modifies the network underlying this, manager
 * @effects receives request and sends appropriate replies.Returns if either the connection is closed or an error happens. If this happens, removes itself from the manager's connection list.
 */
public void run(){
  Assert.that(sock != null && in != null && out != null,"String_Node_Str");
  Assert.that(manager != null && routeTable != null && pushRouteTable != null,"String_Node_Str");
  try {
    sock.setSoTimeout(SettingsManager.instance().getTimeout());
  }
 catch (  SocketException e) {
  }
  try {
    while (true) {
      Message m=null;
      try {
        m=receive();
        if (m == null)         continue;
      }
 catch (      BadPacketException e) {
        continue;
      }
      if (m instanceof PingRequest) {
        Connection inConnection=routeTable.get(m.getGUID());
        if (inConnection == null && !isRouteSpam(m)) {
          if (manager.stats == true)           manager.PReqCount++;
          if (m.hop() != 0) {
            routeTable.put(m.getGUID(),this);
            manager.sendToAllExcept(m,this);
            byte[] ip=sock.getLocalAddress().getAddress();
            FileManager fm=FileManager.getFileManager();
            int kilobytes=fm.getSize();
            int num_files=fm.getNumFiles();
            Message pingReply=new PingReply(m.getGUID(),(byte)(m.getHops() + 1),manager.getListeningPort(),ip,num_files,kilobytes);
            send(pingReply);
            if (manager.stats == true)             manager.PRepCount++;
          }
 else {
          }
        }
 else {
        }
      }
 else       if (m instanceof PingReply) {
        Connection outConnection=routeTable.get(m.getGUID());
        manager.catcher.spy(m);
        if (outConnection != null && routeFilter.allow(m)) {
          if (manager.stats == true)           manager.PRepCount++;
          if (outConnection.equals(manager.ME_CONNECTION)) {
            totalFileSize+=((PingReply)m).getKbytes();
            numFiles+=((PingReply)m).getFiles();
            numHosts++;
          }
 else {
            m.hop();
            outConnection.send(m);
          }
        }
 else {
          dropped++;
        }
      }
 else       if (m instanceof QueryRequest) {
        Connection inConnection=routeTable.get(m.getGUID());
        if (inConnection == null && !isRouteSpam(m)) {
          ActivityCallback ui=manager.getCallback();
          if (ui != null && personalFilter.allow(m))           ui.handleQueryString(((QueryRequest)m).getQuery());
          manager.QReqCount++;
          if (m.hop() != 0) {
            routeTable.put(m.getGUID(),this);
            manager.sendToAllExcept(m,this);
            FileManager fm=FileManager.getFileManager();
            Response[] responses=fm.query((QueryRequest)m);
            if (responses.length > 0) {
              byte[] guid=m.getGUID();
              byte ttl=(byte)(m.getHops() + 1);
              int port=manager.getListeningPort();
              byte[] ip=sock.getLocalAddress().getAddress();
              long speed=SettingsManager.instance().getConnectionSpeed();
              byte[] clientGUID=manager.ClientId.bytes();
              if (responses.length > 255) {
                Response[] res=new Response[255];
                for (int i=0; i < 255; i++)                 res[i]=responses[i];
                responses=res;
              }
              QueryReply qreply=new QueryReply(guid,ttl,port,ip,speed,responses,clientGUID);
              send(qreply);
              if (manager.stats == true)               manager.QRepCount++;
            }
          }
 else {
          }
        }
 else {
        }
      }
 else       if (m instanceof QueryReply) {
        Connection outConnection=routeTable.get(m.getGUID());
        if (outConnection != null && routeFilter.allow(m)) {
          if (manager.stats == true)           manager.QRepCount++;
          QueryReply qrep=(QueryReply)m;
          pushRouteTable.put(qrep.getClientGUID(),this);
          if (outConnection.equals(manager.ME_CONNECTION)) {
            ActivityCallback ui=manager.getCallback();
            if (ui != null && personalFilter.allow(m))             ui.handleQueryReply((QueryReply)m);
          }
 else {
            m.hop();
            outConnection.send(m);
          }
        }
 else {
          dropped++;
        }
      }
 else       if (m instanceof PushRequest) {
        if (manager.stats == true)         manager.pushCount++;
        PushRequest req=(PushRequest)m;
        byte[] req_guid=req.getClientGUID();
        String req_guid_hexstring=(new GUID(req_guid)).toString();
        Connection nextHost=pushRouteTable.get(req_guid);
        if (nextHost != null && routeFilter.allow(m)) {
          m.hop();
          nextHost.send(m);
        }
 else         if (manager.isClient(req_guid)) {
          String host=new String(req.getIP());
          byte[] ip=req.getIP();
          StringBuffer buf=new StringBuffer();
          buf.append(ByteOrder.ubyte2int(ip[0]) + "String_Node_Str");
          buf.append(ByteOrder.ubyte2int(ip[1]) + "String_Node_Str");
          buf.append(ByteOrder.ubyte2int(ip[2]) + "String_Node_Str");
          buf.append(ByteOrder.ubyte2int(ip[3]) + "String_Node_Str");
          String h=buf.toString();
          int port=req.getPort();
          FileManager fmanager=FileManager.getFileManager();
          int index=(int)req.getIndex();
          FileDesc desc;
          try {
            desc=(FileDesc)fmanager._files.get(index);
          }
 catch (          ArrayIndexOutOfBoundsException e) {
            return;
          }
          String file=desc._name;
          HTTPUploader up=new HTTPUploader(h,port,index,req_guid_hexstring,manager);
          Thread t=new Thread(up);
          t.setDaemon(true);
          t.run();
        }
 else {
          dropped++;
        }
      }
    }
  }
 catch (  IOException e) {
    manager.remove(this);
  }
}

Fixed version (ground truth):
/** 
 * Handles core Gnutella request/reply protocol.
 * @requires this is in the CONNECTED state andthe manager to this has been set via setManager
 * @modifies the network underlying this, manager
 * @effects receives request and sends appropriate replies.Returns if either the connection is closed or an error happens. If this happens, removes itself from the manager's connection list.
 */
public void run(){
  Assert.that(sock != null && in != null && out != null,"String_Node_Str");
  Assert.that(manager != null && routeTable != null && pushRouteTable != null,"String_Node_Str");
  try {
    sock.setSoTimeout(SettingsManager.instance().getTimeout());
  }
 catch (  SocketException e) {
  }
  try {
    while (true) {
      Message m=null;
      try {
        m=receive();
        if (m == null)         continue;
      }
 catch (      BadPacketException e) {
        continue;
      }
      if (m instanceof PingRequest) {
        Connection inConnection=routeTable.get(m.getGUID());
        if (inConnection == null && !isRouteSpam(m)) {
          if (manager.stats == true)           manager.PReqCount++;
          if (m.hop() != 0) {
            routeTable.put(m.getGUID(),this);
            manager.sendToAllExcept(m,this);
            byte[] ip=sock.getLocalAddress().getAddress();
            FileManager fm=FileManager.getFileManager();
            int kilobytes=fm.getSize();
            int num_files=fm.getNumFiles();
            Message pingReply=new PingReply(m.getGUID(),(byte)(m.getHops() + 1),manager.getListeningPort(),ip,num_files,kilobytes);
            send(pingReply);
            if (manager.stats == true)             manager.PRepCount++;
          }
 else {
          }
        }
 else {
        }
      }
 else       if (m instanceof PingReply) {
        Connection outConnection=routeTable.get(m.getGUID());
        manager.catcher.spy(m);
        if (outConnection != null && routeFilter.allow(m)) {
          if (manager.stats == true)           manager.PRepCount++;
          if (outConnection.equals(manager.ME_CONNECTION)) {
            totalFileSize+=((PingReply)m).getKbytes();
            numFiles+=((PingReply)m).getFiles();
            numHosts++;
          }
 else {
            m.hop();
            outConnection.send(m);
          }
        }
 else {
          dropped++;
        }
      }
 else       if (m instanceof QueryRequest) {
        Connection inConnection=routeTable.get(m.getGUID());
        if (inConnection == null && !isRouteSpam(m)) {
          ActivityCallback ui=manager.getCallback();
          if (ui != null && personalFilter.allow(m))           ui.handleQueryString(((QueryRequest)m).getQuery());
          manager.QReqCount++;
          if (m.hop() != 0) {
            routeTable.put(m.getGUID(),this);
            manager.sendToAllExcept(m,this);
            FileManager fm=FileManager.getFileManager();
            Response[] responses=fm.query((QueryRequest)m);
            if (responses.length > 0) {
              byte[] guid=m.getGUID();
              byte ttl=(byte)(m.getHops() + 1);
              int port=manager.getListeningPort();
              byte[] ip=sock.getLocalAddress().getAddress();
              long speed=SettingsManager.instance().getConnectionSpeed();
              byte[] clientGUID=manager.ClientId.bytes();
              if (responses.length > 255) {
                Response[] res=new Response[255];
                for (int i=0; i < 255; i++)                 res[i]=responses[i];
                responses=res;
              }
              QueryReply qreply=new QueryReply(guid,ttl,port,ip,speed,responses,clientGUID);
              send(qreply);
              if (manager.stats == true)               manager.QRepCount++;
            }
          }
 else {
          }
        }
 else {
        }
      }
 else       if (m instanceof QueryReply) {
        Connection outConnection=routeTable.get(m.getGUID());
        if (outConnection != null && routeFilter.allow(m)) {
          if (manager.stats == true)           manager.QRepCount++;
          QueryReply qrep=(QueryReply)m;
          pushRouteTable.put(qrep.getClientGUID(),this);
          if (outConnection.equals(manager.ME_CONNECTION)) {
            ActivityCallback ui=manager.getCallback();
            if (ui != null && personalFilter.allow(m))             ui.handleQueryReply((QueryReply)m);
          }
 else {
            m.hop();
            outConnection.send(m);
          }
        }
 else {
          dropped++;
        }
      }
 else       if (m instanceof PushRequest) {
        if (manager.stats == true)         manager.pushCount++;
        PushRequest req=(PushRequest)m;
        byte[] req_guid=req.getClientGUID();
        String req_guid_hexstring=(new GUID(req_guid)).toString();
        Connection nextHost=pushRouteTable.get(req_guid);
        if (nextHost != null && routeFilter.allow(m)) {
          m.hop();
          nextHost.send(m);
        }
 else         if (manager.isClient(req_guid)) {
          String host=new String(req.getIP());
          byte[] ip=req.getIP();
          StringBuffer buf=new StringBuffer();
          buf.append(ByteOrder.ubyte2int(ip[0]) + "String_Node_Str");
          buf.append(ByteOrder.ubyte2int(ip[1]) + "String_Node_Str");
          buf.append(ByteOrder.ubyte2int(ip[2]) + "String_Node_Str");
          buf.append(ByteOrder.ubyte2int(ip[3]) + "String_Node_Str");
          String h=buf.toString();
          int port=req.getPort();
          FileManager fmanager=FileManager.getFileManager();
          int index=(int)req.getIndex();
          FileDesc desc;
          try {
            desc=(FileDesc)fmanager._files.get(index);
          }
 catch (          Exception e) {
            continue;
          }
          String file=desc._name;
          HTTPUploader up=new HTTPUploader(h,port,index,req_guid_hexstring,manager);
          Thread t=new Thread(up);
          t.setDaemon(true);
          t.run();
        }
 else {
          dropped++;
        }
      }
    }
  }
 catch (  IOException e) {
    manager.remove(this);
  }
}