Program: 48184
Project: 48184
Buggy source:
/** 
 * Opens a stream to the given URL.
 * @param url URL pointing to the TCToken.
 * @return Resource as a stream.
 * @throws TCTokenException
 */
public static InputStream getStream(URL url) throws TCTokenException, MalformedURLException, KeyStoreException, IOException, GeneralSecurityException, HttpException, URISyntaxException {
  HttpEntity entity=null;
  boolean finished=false;
  while (!finished) {
    logger.info("String_Node_Str",url);
    String protocol=url.getProtocol();
    String hostname=url.getHost();
    int port=url.getPort();
    if (port == -1) {
      port=url.getDefaultPort();
    }
    String resource=url.getFile();
    if (!"String_Node_Str".equals(protocol)) {
      throw new ControlException("String_Node_Str");
    }
    TlsAuthenticationCertSave tlsAuth=new TlsAuthenticationCertSave();
    tlsAuth.setHostname(hostname);
    ClientCertTlsClient tlsClient=new ClientCertDefaultTlsClient(hostname);
    tlsClient.setAuthentication(tlsAuth);
    tlsClient.setClientVersion(ProtocolVersion.TLSv11);
    Socket socket=ProxySettings.getDefault().getSocket(hostname,port);
    TlsProtocolHandler h=new TlsProtocolHandler(socket.getInputStream(),socket.getOutputStream());
    h.connect(tlsClient);
    StreamHttpClientConnection conn=new StreamHttpClientConnection(h.getInputStream(),h.getOutputStream());
    HttpContext ctx=new BasicHttpContext();
    HttpRequestExecutor httpexecutor=new HttpRequestExecutor();
    BasicHttpEntityEnclosingRequest req=new BasicHttpEntityEnclosingRequest("String_Node_Str",resource);
    req.setParams(conn.getParams());
    HttpRequestHelper.setDefaultHeader(req,hostname);
    req.setHeader("String_Node_Str","String_Node_Str");
    req.setHeader("String_Node_Str","String_Node_Str");
    HttpResponse response=httpexecutor.execute(req,conn,ctx);
    StatusLine status=response.getStatusLine();
    int statusCode=status.getStatusCode();
switch (statusCode) {
case 301:
case 302:
case 303:
case 307:
      Header[] headers=response.getHeaders("String_Node_Str");
    if (headers.length > 0) {
      String uri=headers[0].getValue();
      url=new URL(uri);
    }
 else {
      throw new TCTokenException("String_Node_Str");
    }
  break;
default :
conn.receiveResponseEntity(response);
entity=response.getEntity();
finished=true;
}
}
LimitedInputStream is=new LimitedInputStream(entity.getContent());
return is;
}

Fixed version (ground truth):
/** 
 * Opens a stream to the given URL.
 * @param url URL pointing to the TCToken.
 * @return Resource as a stream.
 * @throws TCTokenException
 */
public static InputStream getStream(URL url) throws TCTokenException, MalformedURLException, KeyStoreException, IOException, GeneralSecurityException, HttpException, URISyntaxException {
  HttpEntity entity=null;
  boolean finished=false;
  while (!finished) {
    logger.info("String_Node_Str",url);
    String protocol=url.getProtocol();
    String hostname=url.getHost();
    int port=url.getPort();
    if (port == -1) {
      port=url.getDefaultPort();
    }
    String resource=url.getFile();
    if (!"String_Node_Str".equals(protocol)) {
      throw new ControlException("String_Node_Str");
    }
    TlsAuthenticationCertSave tlsAuth=new TlsAuthenticationCertSave();
    tlsAuth.setHostname(hostname);
    ClientCertTlsClient tlsClient=new ClientCertDefaultTlsClient(hostname);
    tlsClient.setAuthentication(tlsAuth);
    TlsProtocolHandler h;
    try {
      tlsClient.setClientVersion(ProtocolVersion.TLSv11);
      Socket socket=ProxySettings.getDefault().getSocket(hostname,port);
      h=new TlsProtocolHandler(socket.getInputStream(),socket.getOutputStream());
      h.connect(tlsClient);
    }
 catch (    IOException e) {
      logger.error("String_Node_Str");
      tlsClient.setClientVersion(ProtocolVersion.TLSv10);
      Socket socket=ProxySettings.getDefault().getSocket(hostname,port);
      h=new TlsProtocolHandler(socket.getInputStream(),socket.getOutputStream());
      h.connect(tlsClient);
    }
    StreamHttpClientConnection conn=new StreamHttpClientConnection(h.getInputStream(),h.getOutputStream());
    HttpContext ctx=new BasicHttpContext();
    HttpRequestExecutor httpexecutor=new HttpRequestExecutor();
    BasicHttpEntityEnclosingRequest req=new BasicHttpEntityEnclosingRequest("String_Node_Str",resource);
    req.setParams(conn.getParams());
    HttpRequestHelper.setDefaultHeader(req,hostname);
    req.setHeader("String_Node_Str","String_Node_Str");
    req.setHeader("String_Node_Str","String_Node_Str");
    HttpResponse response=httpexecutor.execute(req,conn,ctx);
    StatusLine status=response.getStatusLine();
    int statusCode=status.getStatusCode();
switch (statusCode) {
case 301:
case 302:
case 303:
case 307:
      Header[] headers=response.getHeaders("String_Node_Str");
    if (headers.length > 0) {
      String uri=headers[0].getValue();
      url=new URL(uri);
    }
 else {
      throw new TCTokenException("String_Node_Str");
    }
  break;
default :
conn.receiveResponseEntity(response);
entity=response.getEntity();
finished=true;
}
}
LimitedInputStream is=new LimitedInputStream(entity.getContent());
return is;
}