Program: 100747
Project: 100747
Buggy source:
/** 
 * To escape a file path to a URI, by using %HH to represent special ASCII characters: 0x00~0x1F, 0x7F, ' ', '<', '>', '#', '%' and '"' and non-ASCII characters (whose value >= 128).
 * @param path The path to be escaped.
 * @return The escaped path.
 */
public static String escapeSpecialAsciiAndNonAscii(final String path){
  int len=path.length(), ch;
  final StringBuffer buffer=new StringBuffer(len * 3);
  if (len >= 2 && path.charAt(1) == ':') {
    ch=Character.toUpperCase(path.charAt(0));
    if (ch >= 'A' && ch <= 'Z') {
      buffer.append('/');
    }
  }
  int i=0;
  for (; i < len; i++) {
    ch=path.charAt(i);
    if (ch >= 128) {
      break;
    }
    if (gNeedEscaping[ch]) {
      buffer.append('%');
      buffer.append(gAfterEscaping1[ch]);
      buffer.append(gAfterEscaping2[ch]);
    }
 else {
      buffer.append((char)ch);
    }
  }
  if (i < len) {
    byte[] bytes;
    byte b;
    try {
      bytes=path.substring(i).getBytes("String_Node_Str");
    }
 catch (    final java.io.UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
    len=bytes.length;
    for (i=0; i < len; i++) {
      b=bytes[i];
      if (b < 0) {
        ch=b + 256;
        buffer.append('%');
        buffer.append(gHexChs[ch >> 4]);
        buffer.append(gHexChs[ch & 0xf]);
      }
 else       if (gNeedEscaping[b]) {
        buffer.append('%');
        buffer.append(gAfterEscaping1[b]);
        buffer.append(gAfterEscaping2[b]);
      }
 else {
        buffer.append((char)b);
      }
    }
  }
  return buffer.toString();
}

Fixed version (ground truth):
/** 
 * To escape a file path to a URI, by using %HH to represent special ASCII characters: 0x00~0x1F, 0x7F, ' ', '<', '>', '#', '%' and '"' and non-ASCII characters (whose value >= 128).
 * @param path The path to be escaped.
 * @return The escaped path.
 */
public static String escapeSpecialAsciiAndNonAscii(final String path){
  int len=path.length(), ch;
  final StringBuilder buffer=new StringBuilder(len * 3);
  if (len >= 2 && path.charAt(1) == ':') {
    ch=Character.toUpperCase(path.charAt(0));
    if (ch >= 'A' && ch <= 'Z') {
      buffer.append('/');
    }
  }
  int i=0;
  for (; i < len; i++) {
    ch=path.charAt(i);
    if (ch >= 128) {
      break;
    }
    if (gNeedEscaping[ch]) {
      buffer.append('%');
      buffer.append(gAfterEscaping1[ch]);
      buffer.append(gAfterEscaping2[ch]);
    }
 else {
      buffer.append((char)ch);
    }
  }
  if (i < len) {
    byte[] bytes;
    byte b;
    try {
      bytes=path.substring(i).getBytes("String_Node_Str");
    }
 catch (    final java.io.UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
    len=bytes.length;
    for (i=0; i < len; i++) {
      b=bytes[i];
      if (b < 0) {
        ch=b + 256;
        buffer.append('%');
        buffer.append(gHexChs[ch >> 4]);
        buffer.append(gHexChs[ch & 0xf]);
      }
 else       if (gNeedEscaping[b]) {
        buffer.append('%');
        buffer.append(gAfterEscaping1[b]);
        buffer.append(gAfterEscaping2[b]);
      }
 else {
        buffer.append((char)b);
      }
    }
  }
  return buffer.toString();
}