Program: 62925
Project: 62925
Buggy source:
@Override public FileSlice getTailSlice(FileConfig fileConfig){
  String filePath=fileConfig.getFilePath();
  if (RdfFileLogUtil.common.isInfo()) {
    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);
  }
  long length=fileInfo.getSize();
  if (length == 0) {
    if (RdfFileLogUtil.common.isInfo()) {
      RdfFileLogUtil.common.info("String_Node_Str" + filePath + "String_Node_Str");
    }
    return new FileSlice(filePath,FileDataTypeEnum.TAIL,0,0);
  }
 else   if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + length);
  }
  if (fileConfig.getFileDataType() == FileDataTypeEnum.BODY || fileConfig.getFileDataType() == FileDataTypeEnum.HEAD) {
    return new FileSlice(fileConfig.getFilePath(),FileDataTypeEnum.TAIL,length,length);
  }
  FileMeta fileMeta=TemplateLoader.load(fileConfig.getTemplatePath(),fileConfig.getTemplateEncoding());
  if (!fileMeta.hasTail()) {
    throw new RdfFileException("String_Node_Str" + fileConfig.getTemplatePath() + "String_Node_Str",RdfErrorEnum.TAIL_NOT_DEFINED);
  }
  int tailRowsAfftected=ProtocolLoader.getRowsAfftected(fileConfig,FileDataTypeEnum.TAIL);
  if (tailRowsAfftected == 0) {
    if (RdfFileLogUtil.common.isInfo()) {
      RdfFileLogUtil.common.info("String_Node_Str" + tailRowsAfftected);
    }
    return new FileSlice(filePath,FileDataTypeEnum.TAIL,length,length);
  }
 else   if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + tailRowsAfftected);
  }
  int bufferSize=OssUtil.OSS_READ_TAIL_BUFFER;
  long start=length - bufferSize;
  if (length < bufferSize) {
    bufferSize=(int)length;
    start=0;
  }
  if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
  }
  InputStream is=storage.getInputStream(filePath,start,bufferSize);
  byte[] bs=OssUtil.read(is,bufferSize);
  if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + bs.length);
    RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
  }
  int idx=bufferSize - 1;
  int tailLineCount=0;
  int count=0;
  if (bs[idx] != '\n' && bs[idx] != '\r') {
    tailLineCount++;
    if (RdfFileLogUtil.common.isDebug()) {
      RdfFileLogUtil.common.debug("String_Node_Str");
    }
  }
  boolean next=true;
  while (next) {
    count++;
    byte b=bs[idx];
switch (b) {
case '\n':
case '\r':
      if (tailLineCount == tailRowsAfftected) {
        count--;
        next=false;
        break;
      }
    int p=idx - 1;
  if (p < 0) {
    if (start > bufferSize) {
      start-=bufferSize;
      if (RdfFileLogUtil.common.isDebug()) {
        RdfFileLogUtil.common.debug("String_Node_Str" + (b == '\n' ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str"+ start+ "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
      }
    }
 else     if (start == 0) {
      next=false;
      RdfFileLogUtil.common.debug("String_Node_Str" + (b == '\n' ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str"+ count);
      break;
    }
 else {
      bufferSize=(int)start;
      start=0;
      RdfFileLogUtil.common.debug("String_Node_Str" + (b == '\n' ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str"+ start+ "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
    }
    if (bufferSize < 0) {
      throw new RdfFileException("String_Node_Str",RdfErrorEnum.UNKOWN);
    }
    idx=bufferSize;
    is=storage.getInputStream(filePath,start,bufferSize);
    bs=OssUtil.read(is,bufferSize);
    p=idx - 1;
  }
if (bs[p] != '\r' && bs[p] != '\n') {
  tailLineCount++;
}
break;
default :
p=idx - 1;
if (p < 0) {
if (start > bufferSize) {
start-=bufferSize;
if (RdfFileLogUtil.common.isDebug()) {
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
}
}
 else if (start == 0) {
next=false;
if (RdfFileLogUtil.common.isDebug()) {
RdfFileLogUtil.common.debug("String_Node_Str" + count);
}
break;
}
 else {
bufferSize=(int)start;
start=0;
if (RdfFileLogUtil.common.isDebug()) {
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
}
}
if (bufferSize < 0) {
throw new RdfFileException("String_Node_Str",RdfErrorEnum.UNKOWN);
}
idx=bufferSize;
is=storage.getInputStream(filePath,start,bufferSize);
bs=OssUtil.read(is,bufferSize);
}
break;
}
idx--;
}
start=length - count;
if (RdfFileLogUtil.common.isInfo()) {
RdfFileLogUtil.common.info("String_Node_Str" + filePath + "String_Node_Str"+ count+ "String_Node_Str"+ start+ "String_Node_Str"+ length);
}
return new FileSlice(filePath,FileDataTypeEnum.TAIL,start,length);
}

Fixed version (ground truth):
@Override public FileSlice getTailSlice(FileConfig fileConfig){
  String filePath=fileConfig.getFilePath();
  if (RdfFileLogUtil.common.isInfo()) {
    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);
  }
  long length=fileInfo.getSize();
  if (length == 0) {
    if (RdfFileLogUtil.common.isInfo()) {
      RdfFileLogUtil.common.info("String_Node_Str" + filePath + "String_Node_Str");
    }
    return new FileSlice(filePath,FileDataTypeEnum.TAIL,0,0);
  }
 else   if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + length);
  }
  if (!fileConfig.isPartial() && (fileConfig.getFileDataType() == FileDataTypeEnum.BODY || fileConfig.getFileDataType() == FileDataTypeEnum.HEAD)) {
    return new FileSlice(fileConfig.getFilePath(),FileDataTypeEnum.TAIL,length,length);
  }
  FileMeta fileMeta=TemplateLoader.load(fileConfig.getTemplatePath(),fileConfig.getTemplateEncoding());
  if (!fileMeta.hasTail()) {
    throw new RdfFileException("String_Node_Str" + fileConfig.getTemplatePath() + "String_Node_Str",RdfErrorEnum.TAIL_NOT_DEFINED);
  }
  int tailRowsAfftected=ProtocolLoader.getRowsAfftected(fileConfig,FileDataTypeEnum.TAIL);
  if (tailRowsAfftected == 0) {
    if (RdfFileLogUtil.common.isInfo()) {
      RdfFileLogUtil.common.info("String_Node_Str" + tailRowsAfftected);
    }
    return new FileSlice(filePath,FileDataTypeEnum.TAIL,length,length);
  }
 else   if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + tailRowsAfftected);
  }
  int bufferSize=OssUtil.OSS_READ_TAIL_BUFFER;
  long start=length - bufferSize;
  if (length < bufferSize) {
    bufferSize=(int)length;
    start=0;
  }
  if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize);
  }
  InputStream is=storage.getInputStream(filePath,start,bufferSize);
  byte[] bs=OssUtil.read(is,bufferSize);
  if (RdfFileLogUtil.common.isDebug()) {
    RdfFileLogUtil.common.debug("String_Node_Str" + bs.length);
    RdfFileLogUtil.common.debug("String_Node_Str" + new String(bs));
  }
  int idx=bufferSize - 1;
  int tailLineCount=0;
  int count=0;
  if (bs[idx] != '\n' && bs[idx] != '\r') {
    tailLineCount++;
    if (RdfFileLogUtil.common.isDebug()) {
      RdfFileLogUtil.common.debug("String_Node_Str");
    }
  }
  boolean next=true;
  while (next) {
    count++;
    byte b=bs[idx];
switch (b) {
case '\n':
case '\r':
      if (tailLineCount == tailRowsAfftected) {
        count--;
        next=false;
        break;
      }
    int p=idx - 1;
  if (p < 0) {
    if (start > bufferSize) {
      start-=bufferSize;
      if (RdfFileLogUtil.common.isDebug()) {
        RdfFileLogUtil.common.debug("String_Node_Str" + (b == '\n' ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str"+ start+ "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
      }
    }
 else     if (start == 0) {
      next=false;
      RdfFileLogUtil.common.debug("String_Node_Str" + (b == '\n' ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str"+ count);
      break;
    }
 else {
      bufferSize=(int)start;
      start=0;
      RdfFileLogUtil.common.debug("String_Node_Str" + (b == '\n' ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str"+ start+ "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
    }
    if (bufferSize < 0) {
      throw new RdfFileException("String_Node_Str",RdfErrorEnum.UNKOWN);
    }
    idx=bufferSize;
    is=storage.getInputStream(filePath,start,bufferSize);
    bs=OssUtil.read(is,bufferSize);
    p=idx - 1;
  }
if (bs[p] != '\r' && bs[p] != '\n') {
  tailLineCount++;
}
break;
default :
p=idx - 1;
if (p < 0) {
if (start > bufferSize) {
start-=bufferSize;
if (RdfFileLogUtil.common.isDebug()) {
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
}
}
 else if (start == 0) {
next=false;
if (RdfFileLogUtil.common.isDebug()) {
RdfFileLogUtil.common.debug("String_Node_Str" + count);
}
break;
}
 else {
bufferSize=(int)start;
start=0;
if (RdfFileLogUtil.common.isDebug()) {
RdfFileLogUtil.common.debug("String_Node_Str" + start + "String_Node_Str"+ bufferSize+ "String_Node_Str"+ count);
}
}
if (bufferSize < 0) {
throw new RdfFileException("String_Node_Str",RdfErrorEnum.UNKOWN);
}
idx=bufferSize;
is=storage.getInputStream(filePath,start,bufferSize);
bs=OssUtil.read(is,bufferSize);
}
break;
}
idx--;
}
start=length - count;
if (RdfFileLogUtil.common.isInfo()) {
RdfFileLogUtil.common.info("String_Node_Str" + filePath + "String_Node_Str"+ count+ "String_Node_Str"+ start+ "String_Node_Str"+ length);
}
return new FileSlice(filePath,FileDataTypeEnum.TAIL,start,length);
}