Program: 133773
Project: 133773
Buggy source:
@Override protected ResourceResponse newResourceResponse(Attributes attributes){
  final WebRequest request=(WebRequest)attributes.getRequest();
  final HttpServletRequest httpRequest=(HttpServletRequest)request.getContainerRequest();
  final PageParameters params=attributes.getParameters();
  final ResourceResponse response=new ResourceResponse();
  if (response.dataNeedsToBeWritten(attributes)) {
    String orientDbHttpURL=OrientDbWebApplication.get().getOrientDbSettings().getOrientDBRestApiUrl();
    if (orientDbHttpURL != null) {
      StringBuilder sb=new StringBuilder(orientDbHttpURL);
      for (int i=0; i < params.getIndexedCount(); i++) {
        if (i == 1) {
          sb.append(OrientDbWebSession.get().getDatabase().getName()).append('/');
        }
 else {
          sb.append(params.get(i).toString()).append('/');
        }
      }
      if (sb.charAt(sb.length() - 1) == '/')       sb.setLength(sb.length() - 1);
      String queryString=request.getUrl().getQueryString();
      if (!Strings.isEmpty(queryString))       sb.append('?').append(queryString);
      final String url=sb.toString();
      final StringWriter sw=new StringWriter();
      final PrintWriter out=new PrintWriter(sw);
      HttpURLConnection con=null;
      try {
        URL orientURL=new URL(url);
        con=(HttpURLConnection)orientURL.openConnection();
        con.setDoInput(true);
        con.setUseCaches(false);
        String method=httpRequest.getMethod();
        con.setRequestMethod(method);
        if ("String_Node_Str".equalsIgnoreCase(method) || "String_Node_Str".equalsIgnoreCase(method)) {
          con.setDoOutput(true);
          IOUtils.copy(httpRequest.getInputStream(),con.getOutputStream());
        }
        IOUtils.copy(con.getInputStream(),out,"String_Node_Str");
        response.setStatusCode(con.getResponseCode());
        response.setContentType(con.getContentType());
      }
 catch (      IOException e) {
        LOG.error("String_Node_Str",e);
        if (con != null) {
          try {
            response.setError(con.getResponseCode(),con.getResponseMessage());
            InputStream errorStream=con.getErrorStream();
            if (errorStream != null)             IOUtils.copy(errorStream,out,"String_Node_Str");
          }
 catch (          IOException e1) {
            LOG.error("String_Node_Str",e1);
          }
        }
      }
      response.setWriteCallback(new WriteCallback(){
        @Override public void writeData(        Attributes attributes) throws IOException {
          attributes.getResponse().write(sw.toString());
        }
      }
);
    }
 else {
      response.setError(HttpServletResponse.SC_BAD_GATEWAY,"String_Node_Str");
    }
  }
  return response;
}

Fixed version (ground truth):
@Override protected ResourceResponse newResourceResponse(Attributes attributes){
  final WebRequest request=(WebRequest)attributes.getRequest();
  final HttpServletRequest httpRequest=(HttpServletRequest)request.getContainerRequest();
  final PageParameters params=attributes.getParameters();
  final ResourceResponse response=new ResourceResponse();
  if (response.dataNeedsToBeWritten(attributes)) {
    String orientDbHttpURL=OrientDbWebApplication.get().getOrientDbSettings().getOrientDBRestApiUrl();
    if (orientDbHttpURL != null) {
      StringBuilder sb=new StringBuilder(orientDbHttpURL);
      for (int i=0; i < params.getIndexedCount(); i++) {
        String segment=i == 1 ? OrientDbWebSession.get().getDatabase().getName() : params.get(i).toString();
        sb.append(UrlEncoder.PATH_INSTANCE.encode(segment,"String_Node_Str")).append('/');
      }
      if (sb.charAt(sb.length() - 1) == '/')       sb.setLength(sb.length() - 1);
      String queryString=request.getUrl().getQueryString();
      if (!Strings.isEmpty(queryString))       sb.append('?').append(queryString);
      final String url=sb.toString();
      final StringWriter sw=new StringWriter();
      final PrintWriter out=new PrintWriter(sw);
      HttpURLConnection con=null;
      try {
        URL orientURL=new URL(url);
        con=(HttpURLConnection)orientURL.openConnection();
        con.setDoInput(true);
        con.setUseCaches(false);
        String method=httpRequest.getMethod();
        con.setRequestMethod(method);
        if ("String_Node_Str".equalsIgnoreCase(method) || "String_Node_Str".equalsIgnoreCase(method)) {
          con.setDoOutput(true);
          IOUtils.copy(httpRequest.getInputStream(),con.getOutputStream());
        }
        IOUtils.copy(con.getInputStream(),out,"String_Node_Str");
        response.setStatusCode(con.getResponseCode());
        response.setContentType(con.getContentType());
      }
 catch (      IOException e) {
        LOG.error("String_Node_Str",e);
        if (con != null) {
          try {
            response.setError(con.getResponseCode(),con.getResponseMessage());
            InputStream errorStream=con.getErrorStream();
            if (errorStream != null)             IOUtils.copy(errorStream,out,"String_Node_Str");
          }
 catch (          IOException e1) {
            LOG.error("String_Node_Str",e1);
          }
        }
      }
      response.setWriteCallback(new WriteCallback(){
        @Override public void writeData(        Attributes attributes) throws IOException {
          attributes.getResponse().write(sw.toString());
        }
      }
);
    }
 else {
      response.setError(HttpServletResponse.SC_BAD_GATEWAY,"String_Node_Str");
    }
  }
  return response;
}