Program: 54987
Project: 54987
Buggy source:
/** 
 * Called from run(); will setup the connection to the rtl_tcp instance
 */
private boolean connect(int timeoutMillis){
  if (socket != null) {
    Log.e(LOGTAG,"String_Node_Str");
    return false;
  }
  try {
    long timeoutTime=System.currentTimeMillis() + timeoutMillis;
    while (socket == null && System.currentTimeMillis() < timeoutTime) {
      try {
        socket=new Socket(ipAddress,port);
      }
 catch (      IOException e) {
      }
      sleep(100);
    }
    if (socket == null) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    socket.setTcpNoDelay(true);
    inputStream=socket.getInputStream();
    outputStream=socket.getOutputStream();
    byte[] buffer=new byte[4];
    if (inputStream.read(buffer,0,buffer.length) != buffer.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    magic=new String(buffer,"String_Node_Str");
    if (inputStream.read(buffer,0,buffer.length) != buffer.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    tuner=buffer[3];
    if (tuner <= 0 || tuner >= TUNER_STRING.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    if (inputStream.read(buffer,0,buffer.length) != buffer.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    Log.i(LOGTAG,"String_Node_Str" + TUNER_STRING[tuner] + "String_Node_Str"+ magic+ "String_Node_Str"+ buffer[3]+ "String_Node_Str"+ ipAddress+ "String_Node_Str"+ port);
    name="String_Node_Str" + TUNER_STRING[tuner] + "String_Node_Str"+ ipAddress+ "String_Node_Str"+ port;
    if (frequency > getMaxFrequency())     frequency=getMaxFrequency();
    if (frequency < getMinFrequency())     frequency=getMinFrequency();
    if (sampleRate > getMaxSampleRate())     sampleRate=getMaxSampleRate();
    if (sampleRate < getMinSampleRate())     sampleRate=getMinSampleRate();
    for (    int gainStep : getPossibleGainValues()) {
      if (gainStep >= gain) {
        gain=gainStep;
        break;
      }
    }
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_FREQUENCY,(int)frequency));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_SAMPLERATE,sampleRate));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_GAIN_MODE,(int)(manualGain ? 0x01 : 0x00)));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_GAIN,gain));
    if (tuner == RTLSDR_TUNER_E4000)     executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_IFGAIN,(short)0,(short)ifGain));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_FREQ_CORR,frequencyCorrection));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_AGC_MODE,(int)(automaticGainControl ? 0x01 : 0x00)));
    return true;
  }
 catch (  UnknownHostException e) {
    Log.e(LOGTAG,"String_Node_Str" + ipAddress);
    reportError("String_Node_Str" + ipAddress);
  }
catch (  IOException e) {
    Log.e(LOGTAG,"String_Node_Str" + ipAddress + "String_Node_Str"+ port+ "String_Node_Str"+ e.getMessage());
  }
catch (  InterruptedException e) {
    Log.e(LOGTAG,"String_Node_Str");
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Called from run(); will setup the connection to the rtl_tcp instance
 */
private boolean connect(int timeoutMillis){
  if (socket != null) {
    Log.e(LOGTAG,"String_Node_Str");
    return false;
  }
  try {
    long timeoutTime=System.currentTimeMillis() + timeoutMillis;
    while (socket == null && System.currentTimeMillis() < timeoutTime) {
      try {
        socket=new Socket(ipAddress,port);
      }
 catch (      IOException e) {
      }
      sleep(100);
    }
    if (socket == null) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    socket.setTcpNoDelay(true);
    socket.setSoTimeout(1000);
    inputStream=socket.getInputStream();
    outputStream=socket.getOutputStream();
    byte[] buffer=new byte[4];
    if (inputStream.read(buffer,0,buffer.length) != buffer.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    magic=new String(buffer,"String_Node_Str");
    if (inputStream.read(buffer,0,buffer.length) != buffer.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    tuner=buffer[3];
    if (tuner <= 0 || tuner >= TUNER_STRING.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    if (inputStream.read(buffer,0,buffer.length) != buffer.length) {
      Log.e(LOGTAG,"String_Node_Str");
      return false;
    }
    Log.i(LOGTAG,"String_Node_Str" + TUNER_STRING[tuner] + "String_Node_Str"+ magic+ "String_Node_Str"+ buffer[3]+ "String_Node_Str"+ ipAddress+ "String_Node_Str"+ port);
    name="String_Node_Str" + TUNER_STRING[tuner] + "String_Node_Str"+ ipAddress+ "String_Node_Str"+ port;
    if (frequency > getMaxFrequency())     frequency=getMaxFrequency();
    if (frequency < getMinFrequency())     frequency=getMinFrequency();
    if (sampleRate > getMaxSampleRate())     sampleRate=getMaxSampleRate();
    if (sampleRate < getMinSampleRate())     sampleRate=getMinSampleRate();
    for (    int gainStep : getPossibleGainValues()) {
      if (gainStep >= gain) {
        gain=gainStep;
        break;
      }
    }
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_FREQUENCY,(int)frequency));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_SAMPLERATE,sampleRate));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_GAIN_MODE,(int)(manualGain ? 0x01 : 0x00)));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_GAIN,gain));
    if (tuner == RTLSDR_TUNER_E4000)     executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_IFGAIN,(short)0,(short)ifGain));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_FREQ_CORR,frequencyCorrection));
    executeCommand(commandToByteArray(RTL_TCP_COMMAND_SET_AGC_MODE,(int)(automaticGainControl ? 0x01 : 0x00)));
    return true;
  }
 catch (  UnknownHostException e) {
    Log.e(LOGTAG,"String_Node_Str" + ipAddress);
    reportError("String_Node_Str" + ipAddress);
  }
catch (  IOException e) {
    Log.e(LOGTAG,"String_Node_Str" + ipAddress + "String_Node_Str"+ port+ "String_Node_Str"+ e.getMessage());
  }
catch (  InterruptedException e) {
    Log.e(LOGTAG,"String_Node_Str");
  }
  return false;
}