nus-yam/ex-repair huggingface dataset:
Program: 90523
Project: 90523
Buggy source:
@Test public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
  final String javaHome=System.getProperty("String_Node_Str");
  final String javaBin=javaHome + File.separator + "String_Node_Str"+ File.separator+ "String_Node_Str";
  final String classpath=System.getProperty("String_Node_Str");
  final String javaagent="String_Node_Str" + agentJar();
  final File tempFile=File.createTempFile("String_Node_Str","String_Node_Str");
  tempFile.deleteOnExit();
  final ProcessBuilder builder=new ProcessBuilder(javaBin,javaagent,"String_Node_Str",classpath,GcFreeLoggingTest.class.getName());
  builder.redirectError(ProcessBuilder.Redirect.to(tempFile));
  builder.redirectOutput(ProcessBuilder.Redirect.to(tempFile));
  final Process process=builder.start();
  process.waitFor();
  process.exitValue();
  final String output=new String(Files.readAllBytes(tempFile.toPath()));
  final String NEWLINE=System.getProperty("String_Node_Str");
  assertEquals("String_Node_Str" + NEWLINE,output);
}

Fixed version (ground truth):
@Test public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
  if (!Constants.ENABLE_THREADLOCALS || !Constants.ENABLE_DIRECT_ENCODERS) {
    return;
  }
  final String javaHome=System.getProperty("String_Node_Str");
  final String javaBin=javaHome + File.separator + "String_Node_Str"+ File.separator+ "String_Node_Str";
  final String classpath=System.getProperty("String_Node_Str");
  final String javaagent="String_Node_Str" + agentJar();
  final File tempFile=File.createTempFile("String_Node_Str","String_Node_Str");
  tempFile.deleteOnExit();
  final ProcessBuilder builder=new ProcessBuilder(javaBin,javaagent,"String_Node_Str",classpath,GcFreeLoggingTest.class.getName());
  builder.redirectError(ProcessBuilder.Redirect.to(tempFile));
  builder.redirectOutput(ProcessBuilder.Redirect.to(tempFile));
  final Process process=builder.start();
  process.waitFor();
  process.exitValue();
  final String output=new String(Files.readAllBytes(tempFile.toPath()));
  final String NEWLINE=System.getProperty("String_Node_Str");
  assertEquals("String_Node_Str" + NEWLINE,output);
}
Program: 90524
Project: 90524
Buggy source:
private void init(String messagePattern){
  this.messagePattern=messagePattern;
  this.indices=new int[messagePattern == null ? 0 : messagePattern.length() << 1];
  int usedCount=ParameterFormatter.countArgumentPlaceholders2(messagePattern,indices);
  initThrowable(argArray,usedCount);
  this.usedCount=Math.min(usedCount,(argArray == null) ? 0 : argArray.length);
}

Fixed version (ground truth):
private void init(String messagePattern){
  this.messagePattern=messagePattern;
  this.indices=new int[messagePattern == null ? 0 : messagePattern.length() >> 1];
  int usedCount=ParameterFormatter.countArgumentPlaceholders2(messagePattern,indices);
  initThrowable(argArray,usedCount);
  this.usedCount=Math.min(usedCount,(argArray == null) ? 0 : argArray.length);
}
Program: 90525
Project: 90525
Buggy source:
/** 
 * Counts the number of unescaped placeholders in the given messagePattern.
 * @param messagePattern the message pattern to be analyzed.
 * @return the number of unescaped placeholders.
 */
static int countArgumentPlaceholders2(final String messagePattern,final int[] indices){
  if (messagePattern == null) {
    return 0;
  }
  int length=messagePattern.length();
  int result=0;
  boolean isEscaped=false;
  for (int i=0; i < length - 1; i++) {
    final char curChar=messagePattern.charAt(i);
    if (curChar == ESCAPE_CHAR) {
      isEscaped=!isEscaped;
      indices[0]=-1;
    }
 else     if (curChar == DELIM_START) {
      if (!isEscaped && messagePattern.charAt(i + 1) == DELIM_STOP) {
        indices[result]=i;
        result++;
        i++;
      }
      isEscaped=false;
    }
 else {
      isEscaped=false;
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Counts the number of unescaped placeholders in the given messagePattern.
 * @param messagePattern the message pattern to be analyzed.
 * @return the number of unescaped placeholders.
 */
static int countArgumentPlaceholders2(final String messagePattern,final int[] indices){
  if (messagePattern == null) {
    return 0;
  }
  int length=messagePattern.length();
  int result=0;
  boolean isEscaped=false;
  for (int i=0; i < length - 1; i++) {
    final char curChar=messagePattern.charAt(i);
    if (curChar == ESCAPE_CHAR) {
      isEscaped=!isEscaped;
      indices[0]=-1;
      result++;
    }
 else     if (curChar == DELIM_START) {
      if (!isEscaped && messagePattern.charAt(i + 1) == DELIM_STOP) {
        indices[result]=i;
        result++;
        i++;
      }
      isEscaped=false;
    }
 else {
      isEscaped=false;
    }
  }
  return result;
}
Program: 90526
Project: 90526
Buggy source:
private void init(final String messagePattern,final int argCount,final Object[] paramArray){
  this.varargs=null;
  this.messagePattern=messagePattern;
  int usedCount=count(messagePattern,indices);
  initThrowable(paramArray,argCount,usedCount);
  this.argCount=Math.min(usedCount,argCount);
}

Fixed version (ground truth):
private void init(final String messagePattern,final int argCount,final Object[] paramArray){
  this.varargs=null;
  this.messagePattern=messagePattern;
  this.argCount=argCount;
  int placeholderCount=count(messagePattern,indices);
  initThrowable(paramArray,argCount,placeholderCount);
  this.usedCount=Math.min(placeholderCount,argCount);
}
Program: 90527
Project: 90527
Buggy source:
@Override public void formatTo(final StringBuilder buffer){
  if (indices[0] < 0) {
    ParameterFormatter.formatMessage(buffer,messagePattern,getParams(),argCount);
  }
 else {
    ParameterFormatter.formatMessage2(buffer,messagePattern,getParams(),argCount,indices);
  }
}

Fixed version (ground truth):
@Override public void formatTo(final StringBuilder buffer){
  if (indices[0] < 0) {
    ParameterFormatter.formatMessage(buffer,messagePattern,getParams(),argCount);
  }
 else {
    ParameterFormatter.formatMessage2(buffer,messagePattern,getParams(),usedCount,indices);
  }
}
Program: 90528
Project: 90528
Buggy source:
private void logDebugNormalApi(){
  root.debug("String_Node_Str",1,2,3);
  root.debug("String_Node_Str",2,3);
  root.debug("String_Node_Str",5,6);
  root.debug("String_Node_Str",7,8,9,10);
}

Fixed version (ground truth):
private void logDebugNormalApi(){
  root.debug("String_Node_Str",1,2,3);
  root.debug("String_Node_Str",2,3);
  root.debug(null,5,6);
  root.debug("String_Node_Str",7,8,9,10);
}
Program: 90529
Project: 90529
Buggy source:
private StringBuilder getBuffer(){
  StringBuilder result=buffer.get();
  if (result == null) {
    result=new StringBuilder(Math.min(512,messagePattern.length() * 2));
    buffer.set(result);
  }
  result.setLength(0);
  return result;
}

Fixed version (ground truth):
private StringBuilder getBuffer(){
  StringBuilder result=buffer.get();
  if (result == null) {
    final int currentPatternLength=messagePattern == null ? 0 : messagePattern.length();
    result=new StringBuilder(Math.min(512,currentPatternLength * 2));
    buffer.set(result);
  }
  result.setLength(0);
  return result;
}
Program: 90530
Project: 90530
Buggy source:
@Setup(Level.Trial) public void up(){
  new File("String_Node_Str").delete();
  System.setProperty("String_Node_Str","String_Node_Str");
  System.setProperty("String_Node_Str","String_Node_Str");
  logger=LogManager.getLogger(getClass());
}

Fixed version (ground truth):
@Setup(Level.Trial) public void up(){
  System.setProperty("String_Node_Str","String_Node_Str");
  System.setProperty("String_Node_Str","String_Node_Str");
  System.setProperty("String_Node_Str","String_Node_Str");
  System.setProperty("String_Node_Str","String_Node_Str");
  logger=LogManager.getLogger(getClass());
  new File("String_Node_Str").delete();
}
Program: 90531
Project: 90531
Buggy source:
private void init(String messagePattern){
  this.messagePattern=messagePattern;
  this.indices=new int[messagePattern == null ? 0 : messagePattern.length() << 1];
  final int usedCount=ParameterFormatter.countArgumentPlaceholders2(messagePattern,indices);
  initThrowable(argArray,usedCount);
}

Fixed version (ground truth):
private void init(String messagePattern){
  this.messagePattern=messagePattern;
  this.indices=new int[messagePattern == null ? 0 : messagePattern.length() << 1];
  int usedCount=ParameterFormatter.countArgumentPlaceholders2(messagePattern,indices);
  initThrowable(argArray,usedCount);
  this.usedCount=Math.min(usedCount,(argArray == null) ? 0 : argArray.length);
}
Program: 90532
Project: 90532
Buggy source:
@Override public void formatTo(final StringBuilder buffer){
  if (formattedMessage != null) {
    buffer.append(formattedMessage);
  }
 else {
    if (indices[0] < 0) {
      ParameterFormatter.formatMessage(buffer,messagePattern,argArray,argArray == null ? 0 : argArray.length);
    }
 else {
      ParameterFormatter.formatMessage2(buffer,messagePattern,argArray,argArray == null ? 0 : argArray.length,indices);
    }
  }
}

Fixed version (ground truth):
@Override public void formatTo(final StringBuilder buffer){
  if (formattedMessage != null) {
    buffer.append(formattedMessage);
  }
 else {
    if (indices[0] < 0) {
      ParameterFormatter.formatMessage(buffer,messagePattern,argArray,usedCount);
    }
 else {
      ParameterFormatter.formatMessage2(buffer,messagePattern,argArray,usedCount,indices);
    }
  }
}
Program: 90533
Project: 90533
Buggy source:
private void init(final String messagePattern,final int argCount,final Object[] paramArray){
  this.varargs=null;
  this.messagePattern=messagePattern;
  this.argCount=argCount;
  int usedCount=count(messagePattern,indices);
  initThrowable(paramArray,usedCount);
}

Fixed version (ground truth):
private void init(final String messagePattern,final int argCount,final Object[] paramArray){
  this.varargs=null;
  this.messagePattern=messagePattern;
  int usedCount=count(messagePattern,indices);
  initThrowable(paramArray,argCount,usedCount);
  this.argCount=Math.min(usedCount,argCount);
}
Program: 90534
Project: 90534
Buggy source:
private void initThrowable(final Object[] params,final int usedParams){
  if (usedParams < argCount && this.throwable == null && params[argCount - 1] instanceof Throwable) {
    this.throwable=(Throwable)params[argCount - 1];
    argCount--;
  }
}

Fixed version (ground truth):
private void initThrowable(final Object[] params,final int argCount,final int usedParams){
  if (usedParams < argCount && this.throwable == null && params[argCount - 1] instanceof Throwable) {
    this.throwable=(Throwable)params[argCount - 1];
  }
}
Program: 90535
Project: 90535
Buggy source:
@Test public void testNoArgs(){
  final String testMsg="String_Node_Str";
  ReusableParameterizedMessage msg=new ReusableParameterizedMessage();
  msg.set(testMsg,null);
  String result=msg.getFormattedMessage();
  assertEquals(testMsg,result);
  msg.set(testMsg,null,null);
  result=msg.getFormattedMessage();
  assertEquals("String_Node_Str",result);
}

Fixed version (ground truth):
@Test public void testNoArgs(){
  final String testMsg="String_Node_Str";
  ReusableParameterizedMessage msg=new ReusableParameterizedMessage();
  msg.set(testMsg,(Object[])null);
  String result=msg.getFormattedMessage();
  assertEquals(testMsg,result);
  msg.set(testMsg,null);
  result=msg.getFormattedMessage();
  assertEquals(testMsg,result);
  msg.set(testMsg,null,null);
  result=msg.getFormattedMessage();
  assertEquals("String_Node_Str",result);
}
Program: 90536
Project: 90536
Buggy source:
/** 
 * Release references held by ring buffer to allow objects to be garbage-collected.
 */
public void clear(){
  setValues(null,null,null,null,null,null,null,null,null,0,null,0,null,0,0);
  trimMessageText();
}

Fixed version (ground truth):
/** 
 * Release references held by ring buffer to allow objects to be garbage-collected.
 */
public void clear(){
  this.asyncLogger=null;
  this.loggerName=null;
  this.marker=null;
  this.fqcn=null;
  this.level=null;
  this.message=null;
  this.thrown=null;
  this.thrownProxy=null;
  this.contextMap=null;
  this.contextStack=null;
  this.location=null;
  trimMessageText();
}
Program: 90537
Project: 90537
Buggy source:
/** 
 * Returns the formatted object message.
 * @return the formatted object message.
 */
@Override public String getFormattedMessage(){
  if (objectString == null) {
    objectString=String.valueOf(obj);
  }
  return objectString;
}

Fixed version (ground truth):
/** 
 * Returns the formatted object message.
 * @return the formatted object message.
 */
@Override public String getFormattedMessage(){
  return String.valueOf(obj);
}
Program: 90538
Project: 90538
Buggy source:
private void init(String messagePattern,int argCount,Object[] paramArray){
  this.varargs=null;
  this.buffer.setLength(0);
  this.messagePattern=messagePattern;
  this.argCount=argCount;
  int usedCount=ParameterFormatter.countArgumentPlaceholders(messagePattern);
  initThrowable(paramArray,usedCount);
}

Fixed version (ground truth):
private void init(String messagePattern,int argCount,Object[] paramArray){
  this.varargs=null;
  this.messagePattern=messagePattern;
  this.argCount=argCount;
  int usedCount=ParameterFormatter.countArgumentPlaceholders(messagePattern);
  initThrowable(paramArray,usedCount);
}
Program: 90539
Project: 90539
Buggy source:
/** 
 * Returns the formatted message.
 * @return the formatted message.
 */
@Override public String getFormattedMessage(){
  formatTo(buffer);
  return buffer.toString();
}

Fixed version (ground truth):
/** 
 * Returns the formatted message.
 * @return the formatted message.
 */
@Override public String getFormattedMessage(){
  final StringBuilder sb=getBuffer();
  formatTo(sb);
  return sb.toString();
}
Program: 90540
Project: 90540
Buggy source:
public void encodeText(final CharSequence text,final ByteBufferDestination destination){
  charsetEncoder.reset();
  ByteBuffer byteBuf=destination.getByteBuffer();
  final CharBuffer charBuf=getCachedCharBuffer();
  int start=0;
  int todoChars=text.length();
  boolean endOfInput=true;
  do {
    charBuf.clear();
    int copied=copy(text,start,charBuf);
    start+=copied;
    todoChars-=copied;
    endOfInput=todoChars <= 0;
    charBuf.flip();
    byteBuf=encode(charBuf,endOfInput,destination,byteBuf);
  }
 while (!endOfInput);
}

Fixed version (ground truth):
public void encodeText(final CharBuffer charBuf,final ByteBufferDestination destination){
  charsetEncoder.reset();
  final ByteBuffer byteBuf=destination.getByteBuffer();
  encode(charBuf,true,destination,byteBuf);
}
Program: 90541
Project: 90541
Buggy source:
/** 
 * Copies characters from the CharSequence into the CharBuffer, starting at the specified offset and ending when either all characters have been copied or when the CharBuffer is full.
 * @return the number of characters that were copied
 */
static int copy(final CharSequence source,final int offset,final CharBuffer destination){
  final int length=Math.min(source.length() - offset,destination.remaining());
  for (int i=offset; i < offset + length; i++) {
    destination.put(source.charAt(i));
  }
  return length;
}

Fixed version (ground truth):
/** 
 * Copies characters from the StringBuilder into the CharBuffer, starting at the specified offset and ending when either all characters have been copied or when the CharBuffer is full.
 * @return the number of characters that were copied
 */
static int copy(final StringBuilder source,final int offset,final CharBuffer destination){
  final int length=Math.min(source.length() - offset,destination.remaining());
  final char[] array=destination.array();
  final int start=destination.position();
  source.getChars(offset,offset + length,array,start);
  destination.position(start + length);
  return length;
}
Program: 90542
Project: 90542
Buggy source:
public void runTestAndPrintResult(final IPerfTestRunner runner,final String name,final int threadCount,final String resultFile) throws Exception {
  final Histogram warmupHist=createHistogram();
  println("String_Node_Str");
  final long t1=System.nanoTime();
  final int LINES=50000;
  int iterations=0;
  final long stop=System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
  do {
    runTest(runner,LINES,null,warmupHist,1);
    iterations++;
  }
 while (System.nanoTime() - stop < 0);
  printf("String_Node_Str",(System.nanoTime() - t1) / (1000.0 * 1000.0 * 1000.0),iterations);
  println("String_Node_Str");
  Thread.sleep(3000);
  Thread.sleep(7000);
  println("String_Node_Str");
  runSingleThreadedTest(runner,LINES * iterations,name,resultFile);
  Thread.sleep(1000);
}

Fixed version (ground truth):
public void runTestAndPrintResult(final IPerfTestRunner runner,final String name,final int threadCount,final String resultFile) throws Exception {
  final Histogram warmupHist=createHistogram();
  println("String_Node_Str");
  final long t1=System.nanoTime();
  final int LINES=50000;
  int iterations=0;
  final long stop=System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
  do {
    runTest(runner,LINES,null,warmupHist,1);
    iterations++;
  }
 while (System.nanoTime() - stop < 0);
  printf("String_Node_Str",(System.nanoTime() - t1) / (1000.0 * 1000.0 * 1000.0),iterations);
  println("String_Node_Str");
  Thread.sleep(3000);
  Thread.sleep(7000);
  println("String_Node_Str");
  runSingleThreadedTest(runner,LINES,name,resultFile);
  Thread.sleep(1000);
}
Program: 90543
Project: 90543
Buggy source:
@Override public void formatTo(final StringBuilder buffer){
  buffer.append(stringBuilder);
  if (stringBuilder.length() > 512) {
    stringBuilder.setLength(512);
    stringBuilder.trimToSize();
  }
}

Fixed version (ground truth):
@Override public void formatTo(final StringBuilder buffer){
  buffer.append(stringBuilder);
  if (stringBuilder.length() > 518) {
    stringBuilder.setLength(518);
    stringBuilder.trimToSize();
  }
}
Program: 90544
Project: 90544
Buggy source:
public void setValues(final AsyncLogger anAsyncLogger,final String aLoggerName,final Marker aMarker,final String theFqcn,final Level aLevel,final Message msg,final Throwable aThrowable,final Map<String,String> aMap,final ContextStack aContextStack,final String aThreadName,final StackTraceElement aLocation,final long aCurrentTimeMillis,final long aNanoTime){
  this.asyncLogger=anAsyncLogger;
  this.loggerName=aLoggerName;
  this.marker=aMarker;
  this.fqcn=theFqcn;
  this.level=aLevel;
  if (msg instanceof ReusableMessage && ((ReusableMessage)msg).isReused()) {
    if (messageText == null) {
      messageText=new StringBuilder(128);
    }
    ((ReusableMessage)msg).formatTo(messageText);
  }
 else {
    this.message=msg;
  }
  this.thrown=aThrowable;
  this.thrownProxy=null;
  this.contextMap=aMap;
  this.contextStack=aContextStack;
  this.threadName=aThreadName;
  this.location=aLocation;
  this.currentTimeMillis=aCurrentTimeMillis;
  this.nanoTime=aNanoTime;
}

Fixed version (ground truth):
public void setValues(final AsyncLogger anAsyncLogger,final String aLoggerName,final Marker aMarker,final String theFqcn,final Level aLevel,final Message msg,final Throwable aThrowable,final Map<String,String> aMap,final ContextStack aContextStack,final String aThreadName,final StackTraceElement aLocation,final long aCurrentTimeMillis,final long aNanoTime){
  this.asyncLogger=anAsyncLogger;
  this.loggerName=aLoggerName;
  this.marker=aMarker;
  this.fqcn=theFqcn;
  this.level=aLevel;
  if (msg instanceof ReusableMessage && ((ReusableMessage)msg).isReused()) {
    if (messageText == null) {
      messageText=new StringBuilder(128);
    }
    messageText.setLength(0);
    ((ReusableMessage)msg).formatTo(messageText);
  }
 else {
    this.message=msg;
  }
  this.thrown=aThrowable;
  this.thrownProxy=null;
  this.contextMap=aMap;
  this.contextStack=aContextStack;
  this.threadName=aThreadName;
  this.location=aLocation;
  this.currentTimeMillis=aCurrentTimeMillis;
  this.nanoTime=aNanoTime;
}
Program: 90545
Project: 90545
Buggy source:
/** 
 * Counts the number of unescaped placeholders in the given messagePattern.
 * @param messagePattern the message pattern to be analyzed.
 * @return the number of unescaped placeholders.
 * @deprecated This method is no longer used internally and is scheduled to be deleted.
 */
public static int countArgumentPlaceholders(final String messagePattern){
  if (messagePattern == null) {
    return 0;
  }
  final int delim=messagePattern.indexOf(DELIM_START);
  if (delim == -1) {
    return 0;
  }
  int result=0;
  boolean isEscaped=false;
  for (int i=0; i < messagePattern.length(); i++) {
    final char curChar=messagePattern.charAt(i);
    if (curChar == ESCAPE_CHAR) {
      isEscaped=!isEscaped;
    }
 else     if (curChar == DELIM_START) {
      if (!isEscaped && i < messagePattern.length() - 1 && messagePattern.charAt(i + 1) == DELIM_STOP) {
        result++;
        i++;
      }
      isEscaped=false;
    }
 else {
      isEscaped=false;
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Counts the number of unescaped placeholders in the given messagePattern.
 * @param messagePattern the message pattern to be analyzed.
 * @return the number of unescaped placeholders.
 */
public static int countArgumentPlaceholders(final String messagePattern){
  if (messagePattern == null) {
    return 0;
  }
  int length=messagePattern.length();
  int result=0;
  boolean isEscaped=false;
  for (int i=0; i < length - 1; i++) {
    final char curChar=messagePattern.charAt(i);
    if (curChar == ESCAPE_CHAR) {
      isEscaped=!isEscaped;
    }
 else     if (curChar == DELIM_START) {
      if (!isEscaped && messagePattern.charAt(i + 1) == DELIM_STOP) {
        result++;
        i++;
      }
      isEscaped=false;
    }
 else {
      isEscaped=false;
    }
  }
  return result;
}
Program: 90546
Project: 90546
Buggy source:
private void initThrowable(final Throwable t){
  if (!isThrowableInitialized && t != null) {
    throwable=t;
  }
  isThrowableInitialized=true;
}

Fixed version (ground truth):
private void initThrowable(final Object[] params,final int usedParams){
  if (usedParams < argCount && this.throwable == null && params[argCount - 1] instanceof Throwable) {
    this.throwable=(Throwable)params[argCount - 1];
    argCount--;
  }
}
Program: 90547
Project: 90547
Buggy source:
@Override public void formatTo(final StringBuilder buffer){
  if (isThreadLocalMessageInitialized) {
    final StringBuilder msg=threadLocalStringBuilder.get();
    if (msg != buffer) {
      buffer.append(msg);
    }
    return;
  }
  final Throwable t=formatMessage(buffer,messagePattern,getParameters(),argCount,throwable);
  initThrowable(t);
  clearUnrolledArgs();
}

Fixed version (ground truth):
@Override public void formatTo(final StringBuilder buffer){
  if (isThreadLocalMessageInitialized) {
    final StringBuilder msg=threadLocalStringBuilder.get();
    if (msg != buffer) {
      buffer.append(msg);
    }
    return;
  }
  formatMessage(buffer,messagePattern,getParameters(),argCount);
  clearUnrolledArgs();
}
Program: 90548
Project: 90548
Buggy source:
/** 
 * Returns the Throwable that was given as the last argument, if any. It will not survive serialization. The Throwable exists as part of the message primarily so that it can be extracted from the end of the list of parameters and then be added to the LogEvent. As such, the Throwable in the event should not be used once the LogEvent has been constructed.
 * @return the Throwable, if any.
 */
@Override public Throwable getThrowable(){
  if (!isThrowableInitialized) {
    initFormattedMessage();
  }
  return throwable;
}

Fixed version (ground truth):
/** 
 * Returns the Throwable that was given as the last argument, if any. It will not survive serialization. The Throwable exists as part of the message primarily so that it can be extracted from the end of the list of parameters and then be added to the LogEvent. As such, the Throwable in the event should not be used once the LogEvent has been constructed.
 * @return the Throwable, if any.
 */
@Override public Throwable getThrowable(){
  return throwable;
}
Program: 90549
Project: 90549
Buggy source:
private void init(String messagePattern,int argCount){
  this.messagePattern=messagePattern;
  this.argCount=argCount;
  this.isThrowableInitialized=false;
  this.isThreadLocalMessageInitialized=false;
}

Fixed version (ground truth):
private void init(String messagePattern,int argCount){
  this.messagePattern=messagePattern;
  this.argCount=argCount;
  this.isThreadLocalMessageInitialized=false;
  int usedCount=countArgumentPlaceholders(messagePattern);
  initThrowable(getParameters(),usedCount);
}
Program: 90550
Project: 90550
Buggy source:
/** 
 * Replace placeholders in the given messagePattern with arguments.
 * @param buffer the buffer to write the formatted message into
 * @param messagePattern the message pattern containing placeholders.
 * @param arguments      the arguments to be used to replace placeholders.
 * @param err the Throwable passed to the constructor (or null if none)
 * @return the Throwable that was the last unused argument in the list, or the specified {@code err} Throwable
 */
private static Throwable formatMessage(final StringBuilder buffer,final String messagePattern,final Object[] arguments,final int argCount,final Throwable err){
  if (messagePattern == null || arguments == null || argCount == 0) {
    buffer.append(messagePattern);
    return err;
  }
  int escapeCounter=0;
  int currentArgument=0;
  int i=0;
  int len=messagePattern.length();
  for (; i < len - 1; i++) {
    final char curChar=messagePattern.charAt(i);
    if (curChar == ESCAPE_CHAR) {
      escapeCounter++;
    }
 else {
      if (isDelimPair(curChar,messagePattern,i)) {
        i++;
        writeEscapedEscapeChars(escapeCounter,buffer);
        if (isOdd(escapeCounter)) {
          writeDelimPair(buffer);
        }
 else {
          writeArgOrDelimPair(arguments,argCount,currentArgument,buffer);
          currentArgument++;
        }
      }
 else {
        handleLiteralChar(buffer,escapeCounter,curChar);
      }
      escapeCounter=0;
    }
  }
  handleRemainingCharIfAny(messagePattern,len,buffer,escapeCounter,i);
  return extractThrowable(arguments,argCount,currentArgument,err);
}

Fixed version (ground truth):
/** 
 * Replace placeholders in the given messagePattern with arguments.
 * @param buffer the buffer to write the formatted message into
 * @param messagePattern the message pattern containing placeholders.
 * @param arguments      the arguments to be used to replace placeholders.
 */
private static void formatMessage(final StringBuilder buffer,final String messagePattern,final Object[] arguments,final int argCount){
  if (messagePattern == null || arguments == null || argCount == 0) {
    buffer.append(messagePattern);
    return;
  }
  int escapeCounter=0;
  int currentArgument=0;
  int i=0;
  int len=messagePattern.length();
  for (; i < len - 1; i++) {
    final char curChar=messagePattern.charAt(i);
    if (curChar == ESCAPE_CHAR) {
      escapeCounter++;
    }
 else {
      if (isDelimPair(curChar,messagePattern,i)) {
        i++;
        writeEscapedEscapeChars(escapeCounter,buffer);
        if (isOdd(escapeCounter)) {
          writeDelimPair(buffer);
        }
 else {
          writeArgOrDelimPair(arguments,argCount,currentArgument,buffer);
          currentArgument++;
        }
      }
 else {
        handleLiteralChar(buffer,escapeCounter,curChar);
      }
      escapeCounter=0;
    }
  }
  handleRemainingCharIfAny(messagePattern,len,buffer,escapeCounter,i);
}
Program: 90551
Project: 90551
Buggy source:
/** 
 * Replace placeholders in the given messagePattern with arguments.
 * @param messagePattern the message pattern containing placeholders.
 * @param arguments      the arguments to be used to replace placeholders.
 * @return the formatted message.
 */
public static String format(final String messagePattern,final Object[] arguments){
  final StringBuilder result=getThreadLocalStringBuilder();
  final int argCount=arguments == null ? 0 : arguments.length;
  formatMessage(result,messagePattern,arguments,argCount,null);
  return result.toString();
}

Fixed version (ground truth):
/** 
 * Replace placeholders in the given messagePattern with arguments.
 * @param messagePattern the message pattern containing placeholders.
 * @param arguments      the arguments to be used to replace placeholders.
 * @return the formatted message.
 */
public static String format(final String messagePattern,final Object[] arguments){
  final StringBuilder result=getThreadLocalStringBuilder();
  final int argCount=arguments == null ? 0 : arguments.length;
  formatMessage(result,messagePattern,arguments,argCount);
  return result.toString();
}
Program: 90552
Project: 90552
Buggy source:
/** 
 * Constructor with a pattern and two parameters.
 * @param messagePattern The message pattern.
 * @param arg0 The first parameter.
 * @param arg1 The second parameter.
 */
public ParameterizedMessage(final String messagePattern,final Object arg0,final Object arg1){
  this.messagePattern=messagePattern;
  Object[] args=unrolledArgs();
  args[0]=arg0;
  args[1]=arg1;
  this.argCount=2;
}

Fixed version (ground truth):
/** 
 * Constructor with a pattern and two parameters.
 * @param messagePattern The message pattern.
 * @param arg0 The first parameter.
 * @param arg1 The second parameter.
 */
public ParameterizedMessage(final String messagePattern,final Object arg0,final Object arg1){
  Object[] args=unrolledArgs();
  args[0]=arg0;
  args[1]=arg1;
  init(messagePattern,2);
}
Program: 90553
Project: 90553
Buggy source:
/** 
 * Creates   {@link ReusableParameterizedMessage} instances.
 * @param message The message pattern.
 * @param params The message parameters.
 * @return The Message.
 * @see MessageFactory#newMessage(String,Object)
 */
@Override public Message newMessage(final String message,final Object... params){
  ReusableParameterizedMessage result=threadLocalMessage.get();
  if (result == null) {
    result=new ReusableParameterizedMessage();
    threadLocalMessage.set(result);
  }
 else {
    result.set(message,params);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Creates   {@link ReusableParameterizedMessage} instances.
 * @param message The message pattern.
 * @param params The message parameters.
 * @return The Message.
 * @see MessageFactory#newMessage(String,Object)
 */
@Override public Message newMessage(final String message,final Object... params){
  ReusableParameterizedMessage result=threadLocalMessage.get();
  if (result == null) {
    result=new ReusableParameterizedMessage();
    threadLocalMessage.set(result);
  }
  result.set(message,params);
  return result;
}
Program: 90554
Project: 90554
Buggy source:
@Override public synchronized void flush(){
  buffer.flip();
  try {
    randomAccessFile.write(buffer.array(),0,buffer.limit());
  }
 catch (  final IOException ex) {
    final String msg="String_Node_Str" + getName();
    throw new AppenderLoggingException(msg,ex);
  }
  buffer.clear();
}

Fixed version (ground truth):
@Override public synchronized void flush(){
  buffer.flip();
  try {
    randomAccessFile.write(buffer.array(),0,buffer.limit());
    size+=buffer.limit();
  }
 catch (  final IOException ex) {
    final String msg="String_Node_Str" + getName();
    throw new AppenderLoggingException(msg,ex);
  }
  buffer.clear();
}
Program: 90555
Project: 90555
Buggy source:
@Override protected synchronized void write(final byte[] bytes,int offset,int length,final boolean immediateFlush){
  super.write(bytes,offset,length,immediateFlush);
  int chunk=0;
  do {
    if (length > buffer.remaining()) {
      flush();
    }
    chunk=Math.min(length,buffer.remaining());
    buffer.put(bytes,offset,chunk);
    offset+=chunk;
    length-=chunk;
  }
 while (length > 0);
  if (immediateFlush || isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
    flush();
  }
}

Fixed version (ground truth):
@Override protected synchronized void write(final byte[] bytes,int offset,int length,final boolean immediateFlush){
  int chunk=0;
  do {
    if (length > buffer.remaining()) {
      flush();
    }
    chunk=Math.min(length,buffer.remaining());
    buffer.put(bytes,offset,chunk);
    offset+=chunk;
    length-=chunk;
  }
 while (length > 0);
  if (immediateFlush || isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
    flush();
  }
}
Program: 90556
Project: 90556
Buggy source:
private static Class<? extends MessageFactory> createClassForProperty(final String property,final Class<ParameterizedMessageFactory> defaultMessageFactoryClass){
  try {
    final String clsName=System.getProperty(property,defaultMessageFactoryClass.getName());
    return Class.forName(clsName).asSubclass(ParameterizedMessageFactory.class);
  }
 catch (  final Throwable t) {
    return defaultMessageFactoryClass;
  }
}

Fixed version (ground truth):
private static Class<? extends MessageFactory> createClassForProperty(final String property,final Class<ParameterizedMessageFactory> defaultMessageFactoryClass){
  try {
    final String clsName=System.getProperty(property,defaultMessageFactoryClass.getName());
    return Class.forName(clsName).asSubclass(MessageFactory.class);
  }
 catch (  final Throwable t) {
    return defaultMessageFactoryClass;
  }
}
Program: 90557
Project: 90557
Buggy source:
@Test public void testRecentFirst() throws Exception {
  SortingVisitor visitor=new SortingVisitor(new PathSortByModificationTime(true));
  Set<FileVisitOption> options=Collections.emptySet();
  Files.walkFileTree(base,options,1,visitor);
  List<PathWithAttributes> found=visitor.getSortedPaths();
  assertNotNull(found);
  assertEquals("String_Node_Str",3,found.size());
  assertEquals("String_Node_Str" + found,ccc,found.get(0));
  assertEquals("String_Node_Str" + found,bbb,found.get(1));
  assertEquals("String_Node_Str" + found,aaa,found.get(2));
}

Fixed version (ground truth):
@Test public void testRecentFirst() throws Exception {
  SortingVisitor visitor=new SortingVisitor(new PathSortByModificationTime(true));
  Set<FileVisitOption> options=Collections.emptySet();
  Files.walkFileTree(base,options,1,visitor);
  List<PathWithAttributes> found=visitor.getSortedPaths();
  assertNotNull(found);
  assertEquals("String_Node_Str",3,found.size());
  assertEquals("String_Node_Str" + found,ccc,found.get(0).getPath());
  assertEquals("String_Node_Str" + found,bbb,found.get(1).getPath());
  assertEquals("String_Node_Str" + found,aaa,found.get(2).getPath());
}
Program: 90558
Project: 90558
Buggy source:
@Test public void testRecentLast() throws Exception {
  SortingVisitor visitor=new SortingVisitor(new PathSortByModificationTime(false));
  Set<FileVisitOption> options=Collections.emptySet();
  Files.walkFileTree(base,options,1,visitor);
  List<PathWithAttributes> found=visitor.getSortedPaths();
  assertNotNull(found);
  assertEquals("String_Node_Str",3,found.size());
  assertEquals("String_Node_Str" + found,aaa,found.get(0));
  assertEquals("String_Node_Str" + found,bbb,found.get(1));
  assertEquals("String_Node_Str" + found,ccc,found.get(2));
}

Fixed version (ground truth):
@Test public void testRecentLast() throws Exception {
  SortingVisitor visitor=new SortingVisitor(new PathSortByModificationTime(false));
  Set<FileVisitOption> options=Collections.emptySet();
  Files.walkFileTree(base,options,1,visitor);
  List<PathWithAttributes> found=visitor.getSortedPaths();
  assertNotNull(found);
  assertEquals("String_Node_Str",3,found.size());
  assertEquals("String_Node_Str" + found,aaa,found.get(0).getPath());
  assertEquals("String_Node_Str" + found,bbb,found.get(1).getPath());
  assertEquals("String_Node_Str" + found,ccc,found.get(2).getPath());
}
Program: 90559
Project: 90559
Buggy source:
private static void copyFile(final File source,final File destination) throws IOException {
  if (!destination.exists()) {
    destination.createNewFile();
  }
  Files.copy(source.toPath(),destination.toPath());
}

Fixed version (ground truth):
private static void copyFile(final File source,final File destination) throws IOException {
  if (!destination.exists()) {
    destination.createNewFile();
  }
  try (FileInputStream srcStream=new FileInputStream(source);FileOutputStream destStream=new FileOutputStream(destination);FileChannel srcChannel=srcStream.getChannel();FileChannel destChannel=destStream.getChannel()){
    destChannel.transferFrom(srcChannel,0,srcChannel.size());
  }
 }
Program: 90560
Project: 90560
Buggy source:
/** 
 * Creates an FileRenameAction.
 * @param src              current file name.
 * @param dst              new file name.
 * @param renameEmptyFiles if true, rename file even if empty, otherwise delete empty files.
 */
public FileRenameAction(final File src,final File dst,final boolean renameEmptyFiles){
  source=src;
  destination=dst;
  this.renameEmptyFiles=renameEmptyFiles;
}

Fixed version (ground truth):
/** 
 * Creates an FileRenameAction.
 * @param src current file name.
 * @param dst new file name.
 * @param renameEmptyFiles if true, rename file even if empty, otherwise delete empty files.
 */
public FileRenameAction(final File src,final File dst,final boolean renameEmptyFiles){
  source=src;
  destination=dst;
  this.renameEmptyFiles=renameEmptyFiles;
}
Program: 90561
Project: 90561
Buggy source:
/** 
 * Rename file.
 * @param source           current file name.
 * @param destination      new file name.
 * @param renameEmptyFiles if true, rename file even if empty, otherwise delete empty files.
 * @return true if successfully renamed.
 */
public static boolean execute(final File source,final File destination,final boolean renameEmptyFiles){
  if (renameEmptyFiles || source.length() > 0) {
    final File parent=destination.getParentFile();
    if (parent != null && !parent.exists()) {
      parent.mkdirs();
      if (!parent.exists()) {
        LOGGER.error("String_Node_Str",parent.getAbsolutePath());
        return false;
      }
    }
    try {
      if (!source.renameTo(destination)) {
        try {
          copyFile(source,destination);
          return source.delete();
        }
 catch (        final IOException iex) {
          LOGGER.error("String_Node_Str",source.getAbsolutePath(),destination.getAbsolutePath(),iex.getMessage());
        }
      }
      return true;
    }
 catch (    final Exception ex) {
      try {
        copyFile(source,destination);
        return source.delete();
      }
 catch (      final IOException iex) {
        LOGGER.error("String_Node_Str",source.getAbsolutePath(),destination.getAbsolutePath(),iex.getMessage());
      }
    }
  }
 else {
    try {
      source.delete();
    }
 catch (    final Exception ex) {
      LOGGER.error("String_Node_Str" + source.getAbsolutePath());
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Rename file.
 * @param source current file name.
 * @param destination new file name.
 * @param renameEmptyFiles if true, rename file even if empty, otherwise delete empty files.
 * @return true if successfully renamed.
 */
public static boolean execute(final File source,final File destination,final boolean renameEmptyFiles){
  if (renameEmptyFiles || source.length() > 0) {
    final File parent=destination.getParentFile();
    if (parent != null && !parent.exists()) {
      parent.mkdirs();
      if (!parent.exists()) {
        LOGGER.error("String_Node_Str",parent.getAbsolutePath());
        return false;
      }
    }
    try {
      if (!source.renameTo(destination)) {
        try {
          copyFile(source,destination);
          return source.delete();
        }
 catch (        final IOException iex) {
          LOGGER.error("String_Node_Str",source.getAbsolutePath(),destination.getAbsolutePath(),iex.getMessage());
        }
      }
      return true;
    }
 catch (    final Exception ex) {
      try {
        copyFile(source,destination);
        return source.delete();
      }
 catch (      final IOException iex) {
        LOGGER.error("String_Node_Str",source.getAbsolutePath(),destination.getAbsolutePath(),iex.getMessage());
      }
    }
  }
 else {
    try {
      source.delete();
    }
 catch (    final Exception ex) {
      LOGGER.error("String_Node_Str" + source.getAbsolutePath());
    }
  }
  return false;
}
Program: 90562
Project: 90562
Buggy source:
@Override public String toString(){
  StringBuilder sb=new StringBuilder();
  if (!(getName().equals(filePath))) {
    sb.append("String_Node_Str").append(getName()).append("String_Node_Str");
  }
  sb.append("String_Node_Str").append(filePath);
  if (getLanguage() != null) {
    sb.append("String_Node_Str").append(getLanguage());
  }
  sb.append("String_Node_Str").append(isWatched);
  return sb.toString();
}

Fixed version (ground truth):
@Override public String toString(){
  StringBuilder sb=new StringBuilder();
  if (!(getName().equals(filePath.toString()))) {
    sb.append("String_Node_Str").append(getName()).append("String_Node_Str");
  }
  sb.append("String_Node_Str").append(filePath);
  if (getLanguage() != null) {
    sb.append("String_Node_Str").append(getLanguage());
  }
  sb.append("String_Node_Str").append(isWatched);
  return sb.toString();
}
Program: 90566
Project: 90566
Buggy source:
private void initializeNonJndi(final String location){
  if (this.name == null) {
    this.name=this.servletContext.getServletContextName();
    LOGGER.debug("String_Node_Str",this.name);
  }
  if (this.name == null && location == null) {
    LOGGER.error("String_Node_Str");
    return;
  }
  final URI uri=getConfigURI(location);
  this.loggerContext=Configurator.initialize(this.name,this.getClassLoader(),uri,this.servletContext);
}

Fixed version (ground truth):
private void initializeNonJndi(final String location){
  if (this.name == null) {
    this.name=this.servletContext.getServletContextName();
    LOGGER.debug("String_Node_Str",this.name);
  }
  if (this.name == null) {
    this.name=this.servletContext.getContextPath();
    LOGGER.debug("String_Node_Str",this.name);
  }
  if (this.name == null && location == null) {
    LOGGER.error("String_Node_Str");
    return;
  }
  final URI uri=getConfigURI(location);
  this.loggerContext=Configurator.initialize(this.name,this.getClassLoader(),uri,this.servletContext);
}
Program: 90567
Project: 90567
Buggy source:
private static Formatter createFormatter(final String[] options){
  Objects.requireNonNull(options);
  if (options.length == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Objects.requireNonNull(options[0]);
  final String patternOption=options[0];
  if (UNIX_FORMAT.equals(patternOption)) {
    return new UnixFormatter();
  }
  if (UNIX_MILLIS_FORMAT.equals(patternOption)) {
    return new UnixMillisFormatter();
  }
  TimeZone tz=null;
  if (options.length > 1) {
    tz=TimeZone.getTimeZone(options[1]);
  }
  try {
    final FastDateFormat tempFormat=FastDateFormat.getInstance(patternOption,tz);
    return new PatternFormatter(tempFormat);
  }
 catch (  final IllegalArgumentException e) {
    LOGGER.warn("String_Node_Str" + patternOption,e);
    return createFormatter(FixedDateFormat.create(FixedFormat.DEFAULT));
  }
}

Fixed version (ground truth):
private static Formatter createFormatter(final String[] options){
  Objects.requireNonNull(options);
  if (options.length == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Objects.requireNonNull(options[0]);
  final String patternOption=options[0];
  if (UNIX_FORMAT.equals(patternOption)) {
    return new UnixFormatter();
  }
  if (UNIX_MILLIS_FORMAT.equals(patternOption)) {
    return new UnixMillisFormatter();
  }
  final FixedDateFormat.FixedFormat fixedFormat=FixedDateFormat.FixedFormat.lookup(patternOption);
  final String pattern=fixedFormat == null ? patternOption : fixedFormat.getPattern();
  TimeZone tz=null;
  if (options.length > 1 && options[1] != null) {
    tz=TimeZone.getTimeZone(options[1]);
  }
  try {
    final FastDateFormat tempFormat=FastDateFormat.getInstance(pattern,tz);
    return new PatternFormatter(tempFormat);
  }
 catch (  final IllegalArgumentException e) {
    LOGGER.warn("String_Node_Str" + pattern,e);
    return createFormatter(FixedDateFormat.create(FixedFormat.DEFAULT));
  }
}
Program: 90568
Project: 90568
Buggy source:
/** 
 * Create the RollingFileManager.
 * @param name The name of the entity to manage.
 * @param data The data required to create the entity.
 * @return a RollingFileManager.
 */
@Override public RollingFileManager createManager(final String name,final FactoryData data){
  final File file=new File(name);
  final File parent=file.getParentFile();
  if (null != parent && !parent.exists()) {
    parent.mkdirs();
  }
  try {
    file.createNewFile();
  }
 catch (  final IOException ioe) {
    LOGGER.error("String_Node_Str" + name,ioe);
    return null;
  }
  final long size=data.append ? file.length() : 0;
  final boolean writeHeader=!data.append || !file.exists();
  OutputStream os;
  try {
    os=new FileOutputStream(name,data.append);
    int bufferSize=data.bufferSize;
    if (data.bufferedIO) {
      os=new BufferedOutputStream(os,bufferSize);
    }
 else {
      bufferSize=-1;
    }
    final long time=file.lastModified();
    return new RollingFileManager(name,data.pattern,os,data.append,size,time,data.policy,data.strategy,data.advertiseURI,data.layout,bufferSize,writeHeader);
  }
 catch (  final FileNotFoundException ex) {
    LOGGER.error("String_Node_Str" + name + "String_Node_Str"+ ex);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Create the RollingFileManager.
 * @param name The name of the entity to manage.
 * @param data The data required to create the entity.
 * @return a RollingFileManager.
 */
@Override public RollingFileManager createManager(final String name,final FactoryData data){
  final File file=new File(name);
  final File parent=file.getParentFile();
  if (null != parent && !parent.exists()) {
    parent.mkdirs();
  }
  final boolean writeHeader=!data.append || !file.exists();
  try {
    file.createNewFile();
  }
 catch (  final IOException ioe) {
    LOGGER.error("String_Node_Str" + name,ioe);
    return null;
  }
  final long size=data.append ? file.length() : 0;
  OutputStream os;
  try {
    os=new FileOutputStream(name,data.append);
    int bufferSize=data.bufferSize;
    if (data.bufferedIO) {
      os=new BufferedOutputStream(os,bufferSize);
    }
 else {
      bufferSize=-1;
    }
    final long time=file.lastModified();
    return new RollingFileManager(name,data.pattern,os,data.append,size,time,data.policy,data.strategy,data.advertiseURI,data.layout,bufferSize,writeHeader);
  }
 catch (  final FileNotFoundException ex) {
    LOGGER.error("String_Node_Str" + name + "String_Node_Str"+ ex);
  }
  return null;
}
Program: 90569
Project: 90569
Buggy source:
/** 
 * Encode the specified string by casting each character to a byte.
 * @param s the string to encode
 * @return the encoded String
 * @see https://issues.apache.org/jira/browse/LOG4J2-1151
 */
private static byte[] encodeSingleByteChars(String s){
  final int length=s.length();
  final byte[] result=new byte[length];
  for (int i=0; i < length; i++) {
    result[i]=(byte)s.charAt(i);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Encode the specified string by casting each character to a byte.
 * @param s the string to encode
 * @return the encoded String
 * @see https://issues.apache.org/jira/browse/LOG4J2-1151
 */
private static byte[] encodeSingleByteChars(String s){
  final int length=s.length();
  final byte[] result=new byte[length];
  encode(s,0,length,result);
  return result;
}
Program: 90570
Project: 90570
Buggy source:
protected AbstractStringLayout(final Charset charset,final byte[] header,final byte[] footer){
  super(header,footer);
  this.charset=charset == null ? StandardCharsets.UTF_8 : charset;
  this.charsetName=this.charset.name();
  isDirectSingleByteMapping=StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset);
}

Fixed version (ground truth):
protected AbstractStringLayout(final Charset charset,final byte[] header,final byte[] footer){
  super(header,footer);
  this.charset=charset == null ? StandardCharsets.UTF_8 : charset;
  this.charsetName=this.charset.name();
  useCustomEncoding=isPreJava8() && (StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset));
}