Program: 86138
Project: 86138
Buggy source:
@Override public ReservationResult reservation(DetailedItem item,Account acc,int useraction,String selection) throws IOException {
  String reservation_info=item.getReservation_info();
  final String branch_inputfield="String_Node_Str";
  Document doc=null;
  String action="String_Node_Str";
  if (reservation_info.contains("String_Node_Str")) {
    action="String_Node_Str";
  }
  if (useraction == MultiStepResult.ACTION_CONFIRMATION) {
    List<NameValuePair> nameValuePairs=new ArrayList<>(2);
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",action));
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
    String html=httpPost(opac_url + "String_Node_Str" + action+ "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING);
    doc=Jsoup.parse(html);
  }
 else   if (selection == null || useraction == 0) {
    String html=httpGet(opac_url + "String_Node_Str" + reservation_info,ENCODING);
    doc=Jsoup.parse(html);
    if (doc.select("String_Node_Str").size() > 0) {
      List<NameValuePair> nameValuePairs=new ArrayList<>(2);
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",acc.getName()));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",acc.getPassword()));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str","String_Node_Str"));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str","String_Node_Str"));
      html=handleLoginMessage(httpPost(opac_url + "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING));
      doc=Jsoup.parse(html);
      if (doc.getElementsByClass("String_Node_Str").size() == 0) {
        logged_in=System.currentTimeMillis();
        logged_in_as=acc;
      }
    }
    if (doc.select("String_Node_Str").size() > 0) {
      List<NameValuePair> nameValuePairs=new ArrayList<>(2);
      nameValuePairs.add(new BasicNameValuePair(branch_inputfield,selection));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",action));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str","String_Node_Str"));
      html=httpPost(opac_url + "String_Node_Str" + action+ "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING);
      doc=Jsoup.parse(html);
    }
    if (doc.select("String_Node_Str" + branch_inputfield + "String_Node_Str").size() > 0) {
      List<Map<String,String>> branches=new ArrayList<>();
      for (      Element option : doc.select("String_Node_Str" + branch_inputfield + "String_Node_Str").first().parent().parent().parent().select("String_Node_Str")) {
        if (option.select("String_Node_Str").size() != 1) {
          continue;
        }
        String value=option.text().trim();
        String key=option.select("String_Node_Str").val();
        Map<String,String> selopt=new HashMap<>();
        selopt.put("String_Node_Str",key);
        selopt.put("String_Node_Str",value);
        branches.add(selopt);
      }
      ReservationResult result=new ReservationResult(MultiStepResult.Status.SELECTION_NEEDED);
      result.setActionIdentifier(ReservationResult.ACTION_BRANCH);
      result.setSelection(branches);
      return result;
    }
  }
 else   if (useraction == ReservationResult.ACTION_BRANCH) {
    List<NameValuePair> nameValuePairs=new ArrayList<>(2);
    nameValuePairs.add(new BasicNameValuePair(branch_inputfield,selection));
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",action));
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
    String html=httpPost(opac_url + "String_Node_Str" + action+ "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING);
    doc=Jsoup.parse(html);
  }
  if (doc == null) {
    return new ReservationResult(MultiStepResult.Status.ERROR);
  }
  if (doc.getElementsByClass("String_Node_Str").size() >= 1) {
    return new ReservationResult(MultiStepResult.Status.ERROR,doc.getElementsByClass("String_Node_Str").get(0).text());
  }
  if (doc.select("String_Node_Str").size() > 0 && doc.select("String_Node_Str").size() >= 2) {
    List<String[]> details=new ArrayList<>();
    for (    String row : doc.select("String_Node_Str").first().html().split("String_Node_Str")) {
      Document frag=Jsoup.parseBodyFragment(row);
      if (frag.text().contains("String_Node_Str")) {
        String[] split=frag.text().split("String_Node_Str");
        if (split.length >= 2) {
          details.add(new String[]{split[0].trim() + "String_Node_Str",split[1].trim()});
        }
      }
 else {
        details.add(new String[]{"String_Node_Str",frag.text().trim()});
      }
    }
    ReservationResult result=new ReservationResult(Status.CONFIRMATION_NEEDED);
    result.setDetails(details);
    return result;
  }
  if (doc.select("String_Node_Str").size() >= 1) {
    String errmsg=doc.select("String_Node_Str").get(0).text();
    if (errmsg.contains("String_Node_Str")) {
      Copy best=null;
      for (      Copy copy : item.getCopies()) {
        if (copy.getResInfo() == null) {
          continue;
        }
        if (best == null) {
          best=copy;
          continue;
        }
        try {
          if (Integer.parseInt(copy.getReservations()) < Long.parseLong(best.getReservations())) {
            best=copy;
          }
 else           if (Integer.parseInt(copy.getReservations()) == Long.parseLong(best.getReservations())) {
            if (copy.getReturnDate().isBefore(best.getReturnDate())) {
              best=copy;
            }
          }
        }
 catch (        NumberFormatException e) {
        }
      }
      if (best != null) {
        item.setReservation_info(best.getResInfo());
        return reservation(item,acc,0,null);
      }
    }
    return new ReservationResult(MultiStepResult.Status.ERROR,errmsg);
  }
  if (doc.select("String_Node_Str").size() >= 1) {
    return new ReservationResult(MultiStepResult.Status.OK,doc.select("String_Node_Str").get(0).text());
  }
  return new ReservationResult(Status.OK);
}

Fixed version (ground truth):
@Override public ReservationResult reservation(DetailedItem item,Account acc,int useraction,String selection) throws IOException {
  String reservation_info=item.getReservation_info();
  final String branch_inputfield="String_Node_Str";
  Document doc=null;
  String action="String_Node_Str";
  if (reservation_info.contains("String_Node_Str")) {
    action="String_Node_Str";
  }
  if (useraction == MultiStepResult.ACTION_CONFIRMATION) {
    List<NameValuePair> nameValuePairs=new ArrayList<>(2);
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",action));
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
    String html=httpPost(opac_url + "String_Node_Str" + action+ "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING);
    doc=Jsoup.parse(html);
  }
 else   if (selection == null || useraction == 0) {
    String html=httpGet(opac_url + "String_Node_Str" + reservation_info,ENCODING);
    doc=Jsoup.parse(html);
    if (doc.select("String_Node_Str").size() > 0) {
      CSId=doc.select("String_Node_Str").val();
      List<NameValuePair> nameValuePairs=new ArrayList<>(2);
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",acc.getName()));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",acc.getPassword()));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str","String_Node_Str"));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str","String_Node_Str"));
      html=handleLoginMessage(httpPost(opac_url + "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING));
      doc=Jsoup.parse(html);
      if (doc.getElementsByClass("String_Node_Str").size() == 0) {
        logged_in=System.currentTimeMillis();
        logged_in_as=acc;
      }
    }
    if (doc.select("String_Node_Str").size() > 0) {
      List<NameValuePair> nameValuePairs=new ArrayList<>(2);
      nameValuePairs.add(new BasicNameValuePair(branch_inputfield,selection));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",action));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
      nameValuePairs.add(new BasicNameValuePair("String_Node_Str","String_Node_Str"));
      html=httpPost(opac_url + "String_Node_Str" + action+ "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING);
      doc=Jsoup.parse(html);
    }
    if (doc.select("String_Node_Str" + branch_inputfield + "String_Node_Str").size() > 0) {
      List<Map<String,String>> branches=new ArrayList<>();
      for (      Element option : doc.select("String_Node_Str" + branch_inputfield + "String_Node_Str").first().parent().parent().parent().select("String_Node_Str")) {
        if (option.select("String_Node_Str").size() != 1) {
          continue;
        }
        String value=option.text().trim();
        String key=option.select("String_Node_Str").val();
        Map<String,String> selopt=new HashMap<>();
        selopt.put("String_Node_Str",key);
        selopt.put("String_Node_Str",value);
        branches.add(selopt);
      }
      ReservationResult result=new ReservationResult(MultiStepResult.Status.SELECTION_NEEDED);
      result.setActionIdentifier(ReservationResult.ACTION_BRANCH);
      result.setSelection(branches);
      return result;
    }
  }
 else   if (useraction == ReservationResult.ACTION_BRANCH) {
    List<NameValuePair> nameValuePairs=new ArrayList<>(2);
    nameValuePairs.add(new BasicNameValuePair(branch_inputfield,selection));
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",action));
    nameValuePairs.add(new BasicNameValuePair("String_Node_Str",CSId));
    String html=httpPost(opac_url + "String_Node_Str" + action+ "String_Node_Str",new UrlEncodedFormEntity(nameValuePairs),ENCODING);
    doc=Jsoup.parse(html);
  }
  if (doc == null) {
    return new ReservationResult(MultiStepResult.Status.ERROR);
  }
  if (doc.getElementsByClass("String_Node_Str").size() >= 1) {
    return new ReservationResult(MultiStepResult.Status.ERROR,doc.getElementsByClass("String_Node_Str").get(0).text());
  }
  if (doc.html().contains("String_Node_Str")) {
    return new ReservationResult(MultiStepResult.Status.ERROR,doc.getElementsByTag("String_Node_Str").get(0).text());
  }
  if (doc.select("String_Node_Str").size() > 0 && doc.select("String_Node_Str").size() >= 2) {
    List<String[]> details=new ArrayList<>();
    for (    String row : doc.select("String_Node_Str").first().html().split("String_Node_Str")) {
      Document frag=Jsoup.parseBodyFragment(row);
      if (frag.text().contains("String_Node_Str")) {
        String[] split=frag.text().split("String_Node_Str");
        if (split.length >= 2) {
          details.add(new String[]{split[0].trim() + "String_Node_Str",split[1].trim()});
        }
      }
 else {
        details.add(new String[]{"String_Node_Str",frag.text().trim()});
      }
    }
    ReservationResult result=new ReservationResult(Status.CONFIRMATION_NEEDED);
    result.setDetails(details);
    return result;
  }
  if (doc.select("String_Node_Str").size() >= 1) {
    String errmsg=doc.select("String_Node_Str").get(0).text();
    if (errmsg.contains("String_Node_Str")) {
      Copy best=null;
      for (      Copy copy : item.getCopies()) {
        if (copy.getResInfo() == null) {
          continue;
        }
        if (best == null) {
          best=copy;
          continue;
        }
        try {
          if (Integer.parseInt(copy.getReservations()) < Long.parseLong(best.getReservations())) {
            best=copy;
          }
 else           if (Integer.parseInt(copy.getReservations()) == Long.parseLong(best.getReservations())) {
            if (copy.getReturnDate().isBefore(best.getReturnDate())) {
              best=copy;
            }
          }
        }
 catch (        NumberFormatException e) {
        }
      }
      if (best != null) {
        item.setReservation_info(best.getResInfo());
        return reservation(item,acc,0,null);
      }
    }
    return new ReservationResult(MultiStepResult.Status.ERROR,errmsg);
  }
  if (doc.select("String_Node_Str").size() >= 1) {
    return new ReservationResult(MultiStepResult.Status.OK,doc.select("String_Node_Str").get(0).text());
  }
  return new ReservationResult(Status.OK);
}