Program: 48065
Project: 48065
Buggy source:
private static ResourceContext getStreamInt(URL url,CertificateValidator v,List<Pair<URL,Certificate>> serverCerts,int maxRedirects) throws IOException, ResourceException, ValidationError, InvalidAddressException {
  try {
    DynamicContext dynCtx=DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    CookieManager cManager=(CookieManager)dynCtx.get(TR03112Keys.COOKIE_MANAGER);
    logger.info("String_Node_Str",url);
    if (maxRedirects == 0) {
      throw new ResourceException(MAX_REDIRECTS);
    }
    maxRedirects--;
    String protocol=url.getProtocol();
    String hostname=url.getHost();
    int port=url.getPort();
    if (port == -1) {
      port=url.getDefaultPort();
    }
    String resource=url.getFile();
    resource=resource.isEmpty() ? "String_Node_Str" : resource;
    if (!"String_Node_Str".equals(protocol)) {
      throw new InvalidAddressException(INVALID_ADDRESS);
    }
    TlsClientProtocol h;
    DynamicAuthentication tlsAuth=new DynamicAuthentication(hostname);
    if (isPKIXVerify()) {
      tlsAuth.addCertificateVerifier(new JavaSecVerifier());
    }
    ClientCertTlsClient tlsClient=new ClientCertDefaultTlsClient(hostname,true);
    tlsClient.setAuthentication(tlsAuth);
    tlsClient.setClientVersion(ProtocolVersion.TLSv12);
    Socket socket=ProxySettings.getDefault().getSocket(hostname,port);
    SecureRandom sr=ReusableSecureRandom.getInstance();
    h=new TlsClientProtocol(socket.getInputStream(),socket.getOutputStream(),sr);
    logger.debug("String_Node_Str");
    h.connect(tlsClient);
    logger.debug("String_Node_Str");
    serverCerts.add(new Pair<>(url,tlsAuth.getServerCertificate()));
    CertificateValidator.VerifierResult verifyResult=v.validate(url,tlsAuth.getServerCertificate());
    if (verifyResult == CertificateValidator.VerifierResult.FINISH) {
      List<Pair<URL,Certificate>> pairs=Collections.unmodifiableList(serverCerts);
      return new ResourceContext(tlsClient,h,pairs);
    }
    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,url);
    req.setHeader("String_Node_Str","String_Node_Str");
    req.setHeader("String_Node_Str","String_Node_Str");
    setCookieHeader(req,cManager,url);
    HttpUtils.dumpHttpRequest(logger,req);
    logger.debug("String_Node_Str");
    HttpResponse response=httpexecutor.execute(req,conn,ctx);
    storeCookies(response,cManager,url);
    logger.debug("String_Node_Str");
    StatusLine status=response.getStatusLine();
    int statusCode=status.getStatusCode();
    String reason=status.getReasonPhrase();
    HttpUtils.dumpHttpResponse(logger,response,null);
    HttpEntity entity=null;
    boolean finished=false;
    if (TR03112Utils.isRedirectStatusCode(statusCode)) {
      Header[] headers=response.getHeaders("String_Node_Str");
      if (headers.length > 0) {
        String uri=headers[0].getValue();
        url=new URL(uri);
      }
 else {
        throw new ResourceException(MISSING_LOCATION_HEADER);
      }
    }
 else     if (statusCode >= 400) {
      logger.debug("String_Node_Str",statusCode,reason);
      throw new InvalidResultStatus(lang.translationForKey(INVALID_RESULT_STATUS,statusCode,reason));
    }
 else {
      if (verifyResult == CertificateValidator.VerifierResult.CONTINUE) {
        throw new InvalidAddressException(INVALID_REFRESH_ADDRESS_NOSOP);
      }
 else {
        conn.receiveResponseEntity(response);
        entity=response.getEntity();
        finished=true;
      }
    }
    if (finished) {
      ResourceContext result=new ResourceContext(tlsClient,h,serverCerts);
      LimitedInputStream is=new LimitedInputStream(entity.getContent());
      result.setStream(is);
      return result;
    }
 else {
      h.close();
      return getStreamInt(url,v,serverCerts,maxRedirects);
    }
  }
 catch (  URISyntaxException ex) {
    throw new IOException(lang.translationForKey(FAILED_PROXY),ex);
  }
catch (  HttpException ex) {
    throw new IOException("String_Node_Str",ex);
  }
}

Fixed version (ground truth):
private static ResourceContext getStreamInt(URL url,CertificateValidator v,List<Pair<URL,Certificate>> serverCerts,int maxRedirects) throws IOException, ResourceException, ValidationError, InvalidAddressException {
  try {
    DynamicContext dynCtx=DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    CookieManager cManager=(CookieManager)dynCtx.get(TR03112Keys.COOKIE_MANAGER);
    logger.info("String_Node_Str",url);
    if (maxRedirects == 0) {
      throw new ResourceException(MAX_REDIRECTS);
    }
    maxRedirects--;
    String protocol=url.getProtocol();
    String hostname=url.getHost();
    int port=url.getPort();
    if (port == -1) {
      port=url.getDefaultPort();
    }
    String resource=url.getFile();
    resource=resource.isEmpty() ? "String_Node_Str" : resource;
    if (!"String_Node_Str".equals(protocol)) {
      throw new InvalidAddressException(INVALID_ADDRESS);
    }
    TlsClientProtocol h;
    DynamicAuthentication tlsAuth=new DynamicAuthentication(hostname);
    if (isPKIXVerify()) {
      tlsAuth.addCertificateVerifier(new JavaSecVerifier());
    }
    ClientCertTlsClient tlsClient=new ClientCertDefaultTlsClient(hostname,true);
    tlsClient.setAuthentication(tlsAuth);
    tlsClient.setClientVersion(ProtocolVersion.TLSv12);
    Socket socket=ProxySettings.getDefault().getSocket(hostname,port);
    SecureRandom sr=ReusableSecureRandom.getInstance();
    h=new TlsClientProtocol(socket.getInputStream(),socket.getOutputStream(),sr);
    logger.debug("String_Node_Str");
    h.connect(tlsClient);
    logger.debug("String_Node_Str");
    serverCerts.add(new Pair<>(url,tlsAuth.getServerCertificate()));
    CertificateValidator.VerifierResult verifyResult=v.validate(url,tlsAuth.getServerCertificate());
    if (verifyResult == CertificateValidator.VerifierResult.FINISH) {
      List<Pair<URL,Certificate>> pairs=Collections.unmodifiableList(serverCerts);
      return new ResourceContext(tlsClient,h,pairs);
    }
    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,url);
    req.setHeader("String_Node_Str","String_Node_Str");
    req.setHeader("String_Node_Str","String_Node_Str");
    setCookieHeader(req,cManager,url);
    HttpUtils.dumpHttpRequest(logger,req);
    logger.debug("String_Node_Str");
    HttpResponse response=httpexecutor.execute(req,conn,ctx);
    storeCookies(response,cManager,url);
    logger.debug("String_Node_Str");
    StatusLine status=response.getStatusLine();
    int statusCode=status.getStatusCode();
    String reason=status.getReasonPhrase();
    HttpUtils.dumpHttpResponse(logger,response,null);
    HttpEntity entity=null;
    boolean finished=false;
    if (TR03112Utils.isRedirectStatusCode(statusCode)) {
      Header[] headers=response.getHeaders("String_Node_Str");
      if (headers.length > 0) {
        String uri=headers[0].getValue();
        url=new URL(uri);
      }
 else {
        throw new ResourceException(MISSING_LOCATION_HEADER);
      }
    }
 else     if (statusCode >= 400) {
      logger.debug("String_Node_Str",statusCode,reason);
      throw new InvalidResultStatus(lang.translationForKey(INVALID_RESULT_STATUS,statusCode,reason));
    }
 else {
      if (verifyResult == CertificateValidator.VerifierResult.CONTINUE) {
        throw new InvalidAddressException(INVALID_REFRESH_ADDRESS_NOSOP);
      }
 else {
        conn.receiveResponseEntity(response);
        entity=response.getEntity();
        finished=true;
      }
    }
    if (finished) {
      assert(entity != null);
      ResourceContext result=new ResourceContext(tlsClient,h,serverCerts);
      LimitedInputStream is=new LimitedInputStream(entity.getContent());
      result.setStream(is);
      return result;
    }
 else {
      h.close();
      return getStreamInt(url,v,serverCerts,maxRedirects);
    }
  }
 catch (  URISyntaxException ex) {
    throw new IOException(lang.translationForKey(FAILED_PROXY),ex);
  }
catch (  HttpException ex) {
    throw new IOException("String_Node_Str",ex);
  }
}