Program: 62926
Project: 62926
Buggy source:
/** 
 * @see com.alipay.rdf.file.interfaces.FileSplitter#getHeadSlice(com.alipay.rdf.file.model.FileConfig)
 */
@Override public FileSlice getHeadSlice(FileConfig fileConfig){
  String filePath=fileConfig.getFilePath();
  RdfFileLogUtil.common.info("String_Node_Str" + filePath);
  FileInfo fileInfo=storage.getFileInfo(filePath);
  if (!fileInfo.isExists()) {
    throw new RdfFileException("String_Node_Str" + filePath + "String_Node_Str",RdfErrorEnum.NOT_EXSIT);
  }
  if (0 == fileInfo.getSize()) {
    RdfFileLogUtil.common.warn("String_Node_Str" + filePath + "String_Node_Str");
    return new FileSlice(filePath,FileDataTypeEnum.HEAD,0,0);
  }
 else {
    RdfFileLogUtil.common.debug("String_Node_Str" + fileInfo.getSize());
  }
  if (fileConfig.getFileDataType() == FileDataTypeEnum.BODY || fileConfig.getFileDataType() == FileDataTypeEnum.TAIL) {
    return new FileSlice(fileConfig.getFilePath(),FileDataTypeEnum.HEAD,0,0);
  }
  FileMeta fileMeta=TemplateLoader.load(fileConfig.getTemplatePath(),fileConfig.getTemplateEncoding());
  if (!fileMeta.hasHead()) {
    throw new RdfFileException("String_Node_Str" + fileConfig.getTemplatePath() + "String_Node_Str",RdfErrorEnum.HEAD_NOT_DEFINED);
  }
  int headRowsAffected=ProtocolLoader.getRowsAfftected(fileConfig,FileDataTypeEnum.HEAD);
  if (headRowsAffected == 0) {
    RdfFileLogUtil.common.info("String_Node_Str" + headRowsAffected);
    return new FileSlice(filePath,FileDataTypeEnum.HEAD,0,0);
  }
 else {
    RdfFileLogUtil.common.debug("String_Node_Str" + headRowsAffected);
  }
  long bufferSize=OssUtil.OSS_READ_HEAD_BUFFER;
  long size=fileInfo.getSize();
  if (size < bufferSize) {
    bufferSize=size;
  }
  long start=0;
  RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
  InputStream is=storage.getInputStream(filePath,start,bufferSize);
  byte[] bs=OssUtil.read(is,(int)bufferSize);
  RdfFileLogUtil.common.debug("String_Node_Str" + bs.length);
  RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
  int headLineCount=0;
  boolean next=true;
  int count=0;
  int idx=0;
  while (next) {
    count++;
switch (bs[idx++]) {
case '\n':
      headLineCount++;
    if (headLineCount == headRowsAffected) {
      next=false;
      break;
    }
  if (idx == bufferSize) {
    RdfFileLogUtil.common.debug("String_Node_Str" + bufferSize + "String_Node_Str"+ bufferSize);
    start=start + bufferSize;
    long left=size - start;
    RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ left);
    if (left == 0) {
      next=false;
      break;
    }
    if (left < bufferSize) {
      bufferSize=left;
      RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
    }
 else {
      RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
    }
    is=storage.getInputStream(filePath,start,bufferSize);
    bs=OssUtil.read(is,(int)bufferSize);
    RdfFileLogUtil.common.debug("String_Node_Str" + count);
    RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
    idx=0;
  }
break;
case '\r':
if (idx < bufferSize) {
if (bs[idx] != '\n') {
  headLineCount++;
}
}
 else if (count == size) {
headLineCount++;
next=false;
}
 else {
RdfFileLogUtil.common.debug("String_Node_Str" + bufferSize + "String_Node_Str"+ bufferSize);
start=start + bufferSize;
long left=size - start;
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ left);
if (left == 0) {
  next=false;
  break;
}
if (left < bufferSize) {
  bufferSize=left;
  RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
 else {
  RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
is=storage.getInputStream(filePath,start,bufferSize);
bs=OssUtil.read(is,(int)bufferSize);
RdfFileLogUtil.common.debug("String_Node_Str" + count);
RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
if (bs[0] != '\n') {
  headLineCount++;
}
idx=0;
}
if (headLineCount == headRowsAffected) {
next=false;
}
break;
default :
if (idx == bufferSize) {
RdfFileLogUtil.common.debug("String_Node_Str" + bufferSize + "String_Node_Str"+ bufferSize);
start=start + bufferSize;
long left=size - start;
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ left);
if (left == 0) {
next=false;
break;
}
if (left < bufferSize) {
bufferSize=left;
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
 else {
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
is=storage.getInputStream(filePath,start,bufferSize);
bs=OssUtil.read(is,(int)bufferSize);
RdfFileLogUtil.common.debug("String_Node_Str" + count);
RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
idx=0;
}
break;
}
}
RdfFileLogUtil.common.info("String_Node_Str" + filePath + "String_Node_Str"+ count);
return new FileSlice(fileConfig.getFilePath(),FileDataTypeEnum.HEAD,0,count);
}

Fixed version (ground truth):
/** 
 * @see com.alipay.rdf.file.interfaces.FileSplitter#getHeadSlice(com.alipay.rdf.file.model.FileConfig)
 */
@Override public FileSlice getHeadSlice(FileConfig fileConfig){
  String filePath=fileConfig.getFilePath();
  RdfFileLogUtil.common.info("String_Node_Str" + filePath);
  FileInfo fileInfo=storage.getFileInfo(filePath);
  if (!fileInfo.isExists()) {
    throw new RdfFileException("String_Node_Str" + filePath + "String_Node_Str",RdfErrorEnum.NOT_EXSIT);
  }
  if (0 == fileInfo.getSize()) {
    RdfFileLogUtil.common.warn("String_Node_Str" + filePath + "String_Node_Str");
    return new FileSlice(filePath,FileDataTypeEnum.HEAD,0,0);
  }
 else {
    RdfFileLogUtil.common.debug("String_Node_Str" + fileInfo.getSize());
  }
  if (!fileConfig.isPartial() && (fileConfig.getFileDataType() == FileDataTypeEnum.BODY || fileConfig.getFileDataType() == FileDataTypeEnum.TAIL)) {
    return new FileSlice(fileConfig.getFilePath(),FileDataTypeEnum.HEAD,0,0);
  }
  FileMeta fileMeta=TemplateLoader.load(fileConfig.getTemplatePath(),fileConfig.getTemplateEncoding());
  if (!fileMeta.hasHead()) {
    throw new RdfFileException("String_Node_Str" + fileConfig.getTemplatePath() + "String_Node_Str",RdfErrorEnum.HEAD_NOT_DEFINED);
  }
  int headRowsAffected=ProtocolLoader.getRowsAfftected(fileConfig,FileDataTypeEnum.HEAD);
  if (headRowsAffected == 0) {
    RdfFileLogUtil.common.info("String_Node_Str" + headRowsAffected);
    return new FileSlice(filePath,FileDataTypeEnum.HEAD,0,0);
  }
 else {
    RdfFileLogUtil.common.debug("String_Node_Str" + headRowsAffected);
  }
  long bufferSize=OssUtil.OSS_READ_HEAD_BUFFER;
  long size=fileInfo.getSize();
  if (size < bufferSize) {
    bufferSize=size;
  }
  long start=0;
  RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
  InputStream is=storage.getInputStream(filePath,start,bufferSize);
  byte[] bs=OssUtil.read(is,(int)bufferSize);
  RdfFileLogUtil.common.debug("String_Node_Str" + bs.length);
  RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
  int headLineCount=0;
  boolean next=true;
  int count=0;
  int idx=0;
  while (next) {
    count++;
switch (bs[idx++]) {
case '\n':
      headLineCount++;
    if (headLineCount == headRowsAffected) {
      next=false;
      break;
    }
  if (idx == bufferSize) {
    RdfFileLogUtil.common.debug("String_Node_Str" + bufferSize + "String_Node_Str"+ bufferSize);
    start=start + bufferSize;
    long left=size - start;
    RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ left);
    if (left == 0) {
      next=false;
      break;
    }
    if (left < bufferSize) {
      bufferSize=left;
      RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
    }
 else {
      RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
    }
    is=storage.getInputStream(filePath,start,bufferSize);
    bs=OssUtil.read(is,(int)bufferSize);
    RdfFileLogUtil.common.debug("String_Node_Str" + count);
    RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
    idx=0;
  }
break;
case '\r':
if (idx < bufferSize) {
if (bs[idx] != '\n') {
  headLineCount++;
}
}
 else if (count == size) {
headLineCount++;
next=false;
}
 else {
RdfFileLogUtil.common.debug("String_Node_Str" + bufferSize + "String_Node_Str"+ bufferSize);
start=start + bufferSize;
long left=size - start;
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ left);
if (left == 0) {
  next=false;
  break;
}
if (left < bufferSize) {
  bufferSize=left;
  RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
 else {
  RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
is=storage.getInputStream(filePath,start,bufferSize);
bs=OssUtil.read(is,(int)bufferSize);
RdfFileLogUtil.common.debug("String_Node_Str" + count);
RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
if (bs[0] != '\n') {
  headLineCount++;
}
idx=0;
}
if (headLineCount == headRowsAffected) {
next=false;
}
break;
default :
if (idx == bufferSize) {
RdfFileLogUtil.common.debug("String_Node_Str" + bufferSize + "String_Node_Str"+ bufferSize);
start=start + bufferSize;
long left=size - start;
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ left);
if (left == 0) {
next=false;
break;
}
if (left < bufferSize) {
bufferSize=left;
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
 else {
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
}
is=storage.getInputStream(filePath,start,bufferSize);
bs=OssUtil.read(is,(int)bufferSize);
RdfFileLogUtil.common.debug("String_Node_Str" + count);
RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
idx=0;
}
break;
}
}
RdfFileLogUtil.common.info("String_Node_Str" + filePath + "String_Node_Str"+ count);
return new FileSlice(fileConfig.getFilePath(),FileDataTypeEnum.HEAD,0,count);
}