nus-yam/ex-repair huggingface dataset:
Program: 60182
Project: 60182
Buggy source:
public void testManualServiceFailWhileStarting() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyFailed(EXCEPTION);
  assertEquals(Arrays.asList(State.STARTING,State.FAILED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testManualServiceFailWhileStarting() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyFailed(EXCEPTION);
  assertEquals(ImmutableList.of(State.STARTING,State.FAILED),listener.getStateHistory());
}
Program: 60183
Project: 60183
Buggy source:
public void testNoOpServiceStartStopIdempotence() throws Exception {
  NoOpService service=new NoOpService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.start();
  assertEquals(State.RUNNING,service.state());
  service.stop();
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testNoOpServiceStartStopIdempotence() throws Exception {
  NoOpService service=new NoOpService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.start();
  assertEquals(State.RUNNING,service.state());
  service.stop();
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(ImmutableList.of(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60184
Project: 60184
Buggy source:
@Override protected void doStart(){
  notifyStarted();
}

Fixed version (ground truth):
@Override protected void doStart(){
}
Program: 60185
Project: 60185
Buggy source:
public void testThreadedServiceStartAndWaitStopAndWait() throws Throwable {
  ThreadedService service=new ThreadedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start().get();
  assertEquals(State.RUNNING,service.state());
  service.awaitRunChecks();
  service.stop().get();
  assertEquals(State.TERMINATED,service.state());
  throwIfSet(thrownByExecutionThread);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testThreadedServiceStartAndWaitStopAndWait() throws Throwable {
  ThreadedService service=new ThreadedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start().get();
  assertEquals(State.RUNNING,service.state());
  service.awaitRunChecks();
  service.stopAndWait();
  assertEquals(State.TERMINATED,service.state());
  throwIfSet(thrownByExecutionThread);
  assertEquals(ImmutableList.of(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60186
Project: 60186
Buggy source:
public void testThrowingServiceStartAndWait() throws Exception {
  StartThrowingService service=new StartThrowingService();
  RecordingListener listener=RecordingListener.record(service);
  try {
    service.startAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals(EXCEPTION,e.getCause());
  }
  assertEquals(Arrays.asList(State.STARTING,State.FAILED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testThrowingServiceStartAndWait() throws Exception {
  StartThrowingService service=new StartThrowingService();
  RecordingListener listener=RecordingListener.record(service);
  try {
    service.startAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals(service.exception,e.getCause());
  }
  assertEquals(ImmutableList.of(State.STARTING,State.FAILED),listener.getStateHistory());
}
Program: 60187
Project: 60187
Buggy source:
synchronized ImmutableList<State> getStateHistory() throws Exception {
  completionLatch.await();
  return ImmutableList.copyOf(stateHistory);
}

Fixed version (ground truth):
ImmutableList<State> getStateHistory() throws Exception {
  completionLatch.await();
synchronized (this) {
    return ImmutableList.copyOf(stateHistory);
  }
}
Program: 60188
Project: 60188
Buggy source:
StateSnapshot(State internalState,boolean shutdownWhenStartupFinishes,Throwable failure){
  checkArgument(!shutdownWhenStartupFinishes || internalState == State.STARTING,"String_Node_Str",internalState);
  checkArgument(!(failure != null ^ internalState == State.FAILED),"String_Node_Str" + "String_Node_Str",internalState,failure);
  this.state=internalState;
  this.shutdownWhenStartupFinishes=shutdownWhenStartupFinishes;
  this.failure=failure;
}

Fixed version (ground truth):
StateSnapshot(State internalState,boolean shutdownWhenStartupFinishes,@Nullable Throwable failure){
  checkArgument(!shutdownWhenStartupFinishes || internalState == State.STARTING,"String_Node_Str",internalState);
  checkArgument(!(failure != null ^ internalState == State.FAILED),"String_Node_Str" + "String_Node_Str",internalState,failure);
  this.state=internalState;
  this.shutdownWhenStartupFinishes=shutdownWhenStartupFinishes;
  this.failure=failure;
}
Program: 60189
Project: 60189
Buggy source:
/** 
 * Copies all characters between the   {@link Readable} and {@link Appendable}objects. Does not close or flush either object.
 * @param from the object to read from
 * @param to the object to write to
 * @return the number of characters copied
 * @throws IOException if an I/O error occurs
 */
public static long copy(Readable from,Appendable to) throws IOException {
  CharBuffer buf=CharBuffer.allocate(BUF_SIZE);
  long total=0;
  while (true) {
    int r=from.read(buf);
    if (r == -1) {
      break;
    }
    buf.flip();
    to.append(buf,0,r);
    total+=r;
  }
  return total;
}

Fixed version (ground truth):
/** 
 * Copies all characters between the   {@link Readable} and {@link Appendable}objects. Does not close or flush either object.
 * @param from the object to read from
 * @param to the object to write to
 * @return the number of characters copied
 * @throws IOException if an I/O error occurs
 */
public static long copy(Readable from,Appendable to) throws IOException {
  CharBuffer buf=CharBuffer.allocate(BUF_SIZE);
  long total=0;
  while (from.read(buf) != -1) {
    buf.flip();
    to.append(buf);
    total+=buf.remaining();
    buf.clear();
  }
  return total;
}
Program: 60190
Project: 60190
Buggy source:
public void testManualServiceStopWhileStarting(){
  ManualSwitchedService service=new ManualSwitchedService();
  service.start();
  assertEquals(State.STARTING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStartCalled);
  service.stop();
  assertEquals(State.STOPPING,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.doStopCalled);
  service.notifyStarted();
  assertEquals(State.STOPPING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStopCalled);
  service.notifyStopped();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
}

Fixed version (ground truth):
public void testManualServiceStopWhileStarting() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  assertEquals(State.STARTING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStartCalled);
  service.stop();
  assertEquals(State.STOPPING,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.doStopCalled);
  service.notifyStarted();
  assertEquals(State.STOPPING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStopCalled);
  service.notifyStopped();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertEquals(Arrays.asList(State.STARTING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60191
Project: 60191
Buggy source:
@Override public void run(){
  service.state();
}

Fixed version (ground truth):
@Override protected void run() throws Exception {
}
Program: 60192
Project: 60192
Buggy source:
@Override public synchronized void running(){
  assertEquals(State.STARTING,Iterables.getOnlyElement(stateHistory));
  stateHistory.add(State.RUNNING);
}

Fixed version (ground truth):
@Override public synchronized void running(){
  assertEquals(State.STARTING,Iterables.getOnlyElement(stateHistory));
  stateHistory.add(State.RUNNING);
  assertEquals(State.RUNNING,service.state());
  assertTrue(service.start().isDone());
  assertEquals(State.RUNNING,service.startAndWait());
}
Program: 60193
Project: 60193
Buggy source:
public void testAddListenerAfterFailureDoesntCauseDeadlock() throws InterruptedException {
  final StartThrowingService service=new StartThrowingService();
  service.start();
  assertEquals(State.FAILED,service.state());
  service.addListener(new RecordingListener(),MoreExecutors.sameThreadExecutor());
  Thread thread=new Thread(){
    @Override public void run(){
      service.state();
    }
  }
;
  thread.start();
  thread.join(100);
  assertFalse(thread + "String_Node_Str",thread.isAlive());
}

Fixed version (ground truth):
public void testAddListenerAfterFailureDoesntCauseDeadlock() throws InterruptedException {
  final StartThrowingService service=new StartThrowingService();
  service.start();
  assertEquals(State.FAILED,service.state());
  service.addListener(new RecordingListener(service),MoreExecutors.sameThreadExecutor());
  Thread thread=new Thread(){
    @Override public void run(){
      service.start();
    }
  }
;
  thread.start();
  thread.join(100);
  assertFalse(thread + "String_Node_Str",thread.isAlive());
}
Program: 60194
Project: 60194
Buggy source:
@Override public synchronized void terminated(State from){
  assertEquals(from,Iterables.getLast(stateHistory,State.NEW));
  stateHistory.add(State.TERMINATED);
}

Fixed version (ground truth):
@Override public synchronized void terminated(State from){
  assertEquals(from,Iterables.getLast(stateHistory,State.NEW));
  stateHistory.add(State.TERMINATED);
  assertEquals(State.TERMINATED,service.state());
  assertTrue(service.start().isDone());
  if (from == State.NEW) {
    assertEquals(State.TERMINATED,service.startAndWait());
  }
  assertTrue(service.stop().isDone());
  assertEquals(State.TERMINATED,service.stopAndWait());
  completionLatch.countDown();
}
Program: 60195
Project: 60195
Buggy source:
public void testStopUnstartedService() throws Exception {
  NoOpService service=new NoOpService();
  RecordingListener listener=new RecordingListener();
  service.addListener(listener,MoreExecutors.sameThreadExecutor());
  Future<State> stopResult=service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(State.TERMINATED,stopResult.get());
  Future<State> startResult=service.start();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(State.TERMINATED,startResult.get());
  assertEquals(State.TERMINATED,Iterables.getOnlyElement(listener.getStateHistory()));
}

Fixed version (ground truth):
public void testStopUnstartedService() throws Exception {
  NoOpService service=new NoOpService();
  RecordingListener listener=RecordingListener.record(service);
  Future<State> stopResult=service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(State.TERMINATED,stopResult.get());
  Future<State> startResult=service.start();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(State.TERMINATED,startResult.get());
  assertEquals(State.TERMINATED,Iterables.getOnlyElement(listener.getStateHistory()));
}
Program: 60196
Project: 60196
Buggy source:
public void testNoOpServiceStartStop(){
  RecordingListener listener=new RecordingListener();
  NoOpService service=new NoOpService();
  service.addListener(listener,MoreExecutors.sameThreadExecutor());
  assertEquals(State.NEW,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.running);
  service.start();
  assertEquals(State.RUNNING,service.state());
  assertTrue(service.isRunning());
  assertTrue(service.running);
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.running);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testNoOpServiceStartStop() throws Exception {
  NoOpService service=new NoOpService();
  RecordingListener listener=RecordingListener.record(service);
  assertEquals(State.NEW,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.running);
  service.start();
  assertEquals(State.RUNNING,service.state());
  assertTrue(service.isRunning());
  assertTrue(service.running);
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.running);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60197
Project: 60197
Buggy source:
public void testManualServiceStartStop(){
  ManualSwitchedService service=new ManualSwitchedService();
  service.start();
  assertEquals(State.STARTING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStartCalled);
  service.notifyStarted();
  assertEquals(State.RUNNING,service.state());
  assertTrue(service.isRunning());
  service.stop();
  assertEquals(State.STOPPING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStopCalled);
  service.notifyStopped();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
}

Fixed version (ground truth):
public void testManualServiceStartStop() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  assertEquals(State.STARTING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStartCalled);
  service.notifyStarted();
  assertEquals(State.RUNNING,service.state());
  assertTrue(service.isRunning());
  service.stop();
  assertEquals(State.STOPPING,service.state());
  assertFalse(service.isRunning());
  assertTrue(service.doStopCalled);
  service.notifyStopped();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60198
Project: 60198
Buggy source:
@Override public synchronized void failed(State from,Throwable failure){
  assertEquals(from,Iterables.getLast(stateHistory));
  stateHistory.add(State.FAILED);
}

Fixed version (ground truth):
@Override public synchronized void failed(State from,Throwable failure){
  assertEquals(from,Iterables.getLast(stateHistory));
  stateHistory.add(State.FAILED);
  assertEquals(State.FAILED,service.state());
  completionLatch.countDown();
}
Program: 60199
Project: 60199
Buggy source:
@Override public synchronized void stopping(State from){
  assertEquals(from,Iterables.getLast(stateHistory));
  stateHistory.add(State.STOPPING);
}

Fixed version (ground truth):
@Override public synchronized void stopping(State from){
  assertEquals(from,Iterables.getLast(stateHistory));
  stateHistory.add(State.STOPPING);
  assertEquals(State.STOPPING,service.state());
  if (from == State.STARTING) {
    assertTrue(service.start().isDone());
    assertEquals(State.STOPPING,service.startAndWait());
  }
}
Program: 60200
Project: 60200
Buggy source:
public void testNoOpServiceStartStopIdempotence() throws Exception {
  NoOpService service=new NoOpService();
  RecordingListener listener=new RecordingListener();
  service.addListener(listener,MoreExecutors.sameThreadExecutor());
  service.start();
  service.start();
  assertEquals(State.RUNNING,service.state());
  service.stop();
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testNoOpServiceStartStopIdempotence() throws Exception {
  NoOpService service=new NoOpService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.start();
  assertEquals(State.RUNNING,service.state());
  service.stop();
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60201
Project: 60201
Buggy source:
public void testThreadedServiceStartAndWaitStopAndWait() throws Throwable {
  ThreadedService service=new ThreadedService();
  RecordingListener listener=new RecordingListener();
  service.addListener(listener,MoreExecutors.sameThreadExecutor());
  service.start().get();
  assertEquals(State.RUNNING,service.state());
  service.awaitRunChecks();
  service.stop().get();
  assertEquals(State.TERMINATED,service.state());
  throwIfSet(thrownByExecutionThread);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testThreadedServiceStartAndWaitStopAndWait() throws Throwable {
  ThreadedService service=new ThreadedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start().get();
  assertEquals(State.RUNNING,service.state());
  service.awaitRunChecks();
  service.stop().get();
  assertEquals(State.TERMINATED,service.state());
  throwIfSet(thrownByExecutionThread);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60202
Project: 60202
Buggy source:
@Override public synchronized void starting(){
  assertTrue(stateHistory.isEmpty());
  stateHistory.add(State.STARTING);
}

Fixed version (ground truth):
@Override public synchronized void starting(){
  assertTrue(stateHistory.isEmpty());
  stateHistory.add(State.STARTING);
  assertEquals(State.STARTING,service.state());
  assertFalse(service.start().isDone());
}
Program: 60203
Project: 60203
Buggy source:
synchronized ImmutableList<State> getStateHistory(){
  return ImmutableList.copyOf(stateHistory);
}

Fixed version (ground truth):
synchronized ImmutableList<State> getStateHistory() throws Exception {
  completionLatch.await();
  return ImmutableList.copyOf(stateHistory);
}
Program: 60204
Project: 60204
Buggy source:
/** 
 * Specifies the maximum weight of entries the cache may contain. Weight is determined using the  {@link Weigher} specified with {@link #weigher}, and use of this method requires a corresponding call to   {@link #weigher} prior to calling {@link #build}. <p>Note that the cache <b>may evict an entry before this limit is exceeded</b>. As the cache size grows close to the maximum, the cache evicts entries that are less likely to be used again. For example, the cache may evict an entry because it hasn't been used recently or very often. <p>When   {@code weight} is zero, elements will be evicted immediately after being loaded intocache. This can be useful in testing, or to disable caching temporarily without a code change. <p>Note that weight is only used to determine whether the cache is over capacity; it has no effect on selecting which entry should be evicted next.
 * @param weight the maximum weight the cache may contain
 * @throws IllegalArgumentException if {@code size} is negative
 * @throws IllegalStateException if a maximum size was already set
 * @since 11.0
 */
public CacheBuilder<K,V> maximumWeight(long weight){
  checkState(this.maximumWeight == UNSET_INT,"String_Node_Str",this.maximumWeight);
  checkState(this.maximumSize == UNSET_INT,"String_Node_Str",this.maximumSize);
  this.maximumWeight=weight;
  checkArgument(weight >= 0,"String_Node_Str");
  return this;
}

Fixed version (ground truth):
/** 
 * Specifies the maximum weight of entries the cache may contain. Weight is determined using the  {@link Weigher} specified with {@link #weigher}, and use of this method requires a corresponding call to   {@link #weigher} prior to calling {@link #build}. <p>Note that the cache <b>may evict an entry before this limit is exceeded</b>. As the cache size grows close to the maximum, the cache evicts entries that are less likely to be used again. For example, the cache may evict an entry because it hasn't been used recently or very often. <p>When   {@code weight} is zero, elements will be evicted immediately after being loaded intocache. This can be useful in testing, or to disable caching temporarily without a code change. <p>Note that weight is only used to determine whether the cache is over capacity; it has no effect on selecting which entry should be evicted next. <p>This feature cannot be used in conjunction with  {@link #maximumSize}.
 * @param weight the maximum total weight of entries the cache may contain
 * @throws IllegalArgumentException if {@code weight} is negative
 * @throws IllegalStateException if a maximum weight or size was already set
 * @since 11.0
 */
public CacheBuilder<K,V> maximumWeight(long weight){
  checkState(this.maximumWeight == UNSET_INT,"String_Node_Str",this.maximumWeight);
  checkState(this.maximumSize == UNSET_INT,"String_Node_Str",this.maximumSize);
  this.maximumWeight=weight;
  checkArgument(weight >= 0,"String_Node_Str");
  return this;
}
Program: 60205
Project: 60205
Buggy source:
/** 
 * Specifies the maximum number of entries the cache may contain. Note that the cache <b>may evict an entry before this limit is exceeded</b>. As the cache size grows close to the maximum, the cache evicts entries that are less likely to be used again. For example, the cache may evict an entry because it hasn't been used recently or very often. <p>When   {@code size} is zero, elements will be evicted immediately after being loaded into thecache. This can be useful in testing, or to disable caching temporarily without a code change.
 * @param size the maximum size of the cache
 * @throws IllegalArgumentException if {@code size} is negative
 * @throws IllegalStateException if a maximum size was already set
 */
public CacheBuilder<K,V> maximumSize(long size){
  checkState(this.maximumSize == UNSET_INT,"String_Node_Str",this.maximumSize);
  checkState(this.maximumWeight == UNSET_INT,"String_Node_Str",this.maximumWeight);
  checkState(this.weigher == null,"String_Node_Str");
  checkArgument(size >= 0,"String_Node_Str");
  this.maximumSize=size;
  return this;
}

Fixed version (ground truth):
/** 
 * Specifies the maximum number of entries the cache may contain. Note that the cache <b>may evict an entry before this limit is exceeded</b>. As the cache size grows close to the maximum, the cache evicts entries that are less likely to be used again. For example, the cache may evict an entry because it hasn't been used recently or very often. <p>When   {@code size} is zero, elements will be evicted immediately after being loaded into thecache. This can be useful in testing, or to disable caching temporarily without a code change. <p>This feature cannot be used in conjunction with  {@link #maximumWeight}.
 * @param size the maximum size of the cache
 * @throws IllegalArgumentException if {@code size} is negative
 * @throws IllegalStateException if a maximum size or weight was already set
 */
public CacheBuilder<K,V> maximumSize(long size){
  checkState(this.maximumSize == UNSET_INT,"String_Node_Str",this.maximumSize);
  checkState(this.maximumWeight == UNSET_INT,"String_Node_Str",this.maximumWeight);
  checkState(this.weigher == null,"String_Node_Str");
  checkArgument(size >= 0,"String_Node_Str");
  this.maximumSize=size;
  return this;
}
Program: 60206
Project: 60206
Buggy source:
/** 
 * Loads a new value for key   {@code key}, possibly asynchronously. While the new value is loading the previous value (if any) will continue to be returned by   {@code get(key)} unless it isevicted. If the new value is loaded successfully it will replace the previous value in the cache; if an exception is thrown while refreshing the previous value will remain, <i>and the exception will be logged (using  {@link java.util.logging.Logger}) and swallowed</i>. <p>Caches loaded by a   {@link CacheLoader} will call {@link CacheLoader#reload} if thecache currently contains a value for  {@code key}, and   {@link CacheLoader#load} otherwise.<p>Returns without doing anything if another thread is currently loading the value for {@code key}. If the cache loader associated with this cache performs refresh asynchronously then this method may return before refresh completes.
 * @since 11.0
 */
void refresh(K key);

Fixed version (ground truth):
/** 
 * Loads a new value for key   {@code key}, possibly asynchronously. While the new value is loading the previous value (if any) will continue to be returned by   {@code get(key)} unless it isevicted. If the new value is loaded successfully it will replace the previous value in the cache; if an exception is thrown while refreshing the previous value will remain, <i>and the exception will be logged (using  {@link java.util.logging.Logger}) and swallowed</i>. <p>Caches loaded by a   {@link CacheLoader} will call {@link CacheLoader#reload} if thecache currently contains a value for  {@code key}, and   {@link CacheLoader#load} otherwise.Loading is asynchronous only if  {@link CacheLoader#reload} was overridden with anasynchronous implementation. <p>Returns without doing anything if another thread is currently loading the value for {@code key}. If the cache loader associated with this cache performs refresh asynchronously then this method may return before refresh completes.
 * @since 11.0
 */
void refresh(K key);
Program: 60207
Project: 60207
Buggy source:
public void testInvalidateDuringLoading() throws InterruptedException, ExecutionException {
  final CountDownLatch computationStarted=new CountDownLatch(2);
  final CountDownLatch letGetFinishSignal=new CountDownLatch(1);
  final CountDownLatch getFinishedSignal=new CountDownLatch(2);
  final String getKey="String_Node_Str";
  final String refreshKey="String_Node_Str";
  final String suffix="String_Node_Str";
  CacheLoader<String,String> computeFunction=new CacheLoader<String,String>(){
    @Override public String load(    String key) throws InterruptedException {
      computationStarted.countDown();
      letGetFinishSignal.await();
      return key + suffix;
    }
  }
;
  final LoadingCache<String,String> cache=CacheBuilder.newBuilder().build(computeFunction);
  ConcurrentMap<String,String> map=cache.asMap();
  map.put(refreshKey,refreshKey);
  new Thread(){
    @Override public void run(){
      cache.getUnchecked(getKey);
      getFinishedSignal.countDown();
    }
  }
.start();
  new Thread(){
    @Override public void run(){
      cache.refresh(refreshKey);
      getFinishedSignal.countDown();
    }
  }
.start();
  computationStarted.await();
  cache.invalidate(getKey);
  cache.invalidate(refreshKey);
  assertFalse(map.containsKey(getKey));
  assertFalse(map.containsKey(refreshKey));
  letGetFinishSignal.countDown();
  getFinishedSignal.await();
  checkNothingLogged();
  assertEquals(2,cache.size());
  assertEquals(getKey + suffix,map.get(getKey));
  assertEquals(refreshKey + suffix,map.get(refreshKey));
}

Fixed version (ground truth):
public void testInvalidateDuringLoading() throws InterruptedException, ExecutionException {
  final CountDownLatch computationStarted=new CountDownLatch(2);
  final CountDownLatch letGetFinishSignal=new CountDownLatch(1);
  final CountDownLatch getFinishedSignal=new CountDownLatch(2);
  final String getKey="String_Node_Str";
  final String refreshKey="String_Node_Str";
  final String suffix="String_Node_Str";
  CacheLoader<String,String> computeFunction=new CacheLoader<String,String>(){
    @Override public String load(    String key) throws InterruptedException {
      computationStarted.countDown();
      letGetFinishSignal.await();
      return key + suffix;
    }
  }
;
  final LoadingCache<String,String> cache=CacheBuilder.newBuilder().build(computeFunction);
  ConcurrentMap<String,String> map=cache.asMap();
  map.put(refreshKey,refreshKey);
  new Thread(){
    @Override public void run(){
      cache.getUnchecked(getKey);
      getFinishedSignal.countDown();
    }
  }
.start();
  new Thread(){
    @Override public void run(){
      cache.refresh(refreshKey);
      getFinishedSignal.countDown();
    }
  }
.start();
  computationStarted.await();
  cache.invalidate(getKey);
  cache.invalidate(refreshKey);
  assertFalse(map.containsKey(getKey));
  assertFalse(map.containsKey(refreshKey));
  letGetFinishSignal.countDown();
  getFinishedSignal.await();
  checkNothingLogged();
  assertEquals(2,cache.size());
  assertEquals(getKey + suffix,map.get(getKey));
  assertEquals(refreshKey + suffix,map.get(refreshKey));
  assertEquals(2,cache.size());
}
Program: 60209
Project: 60209
Buggy source:
@Sequential public void testUnloadableWithoutSecurityManager() throws Exception {
  SecurityManager oldSecurityManager=System.getSecurityManager();
  try {
    System.setSecurityManager(null);
    doTestUnloadable();
  }
  finally {
    System.setSecurityManager(oldSecurityManager);
  }
}

Fixed version (ground truth):
public void testUnloadableWithoutSecurityManager() throws Exception {
  SecurityManager oldSecurityManager=System.getSecurityManager();
  try {
    System.setSecurityManager(null);
    doTestUnloadable();
  }
  finally {
    System.setSecurityManager(oldSecurityManager);
  }
}
Program: 60210
Project: 60210
Buggy source:
@Sequential public void testUnloadableWithSecurityManager() throws Exception {
  Policy oldPolicy=Policy.getPolicy();
  SecurityManager oldSecurityManager=System.getSecurityManager();
  try {
    Policy.setPolicy(new PermissivePolicy());
    System.setSecurityManager(new SecurityManager());
    doTestUnloadable();
  }
  finally {
    System.setSecurityManager(oldSecurityManager);
    Policy.setPolicy(oldPolicy);
  }
}

Fixed version (ground truth):
public void testUnloadableWithSecurityManager() throws Exception {
  Policy oldPolicy=Policy.getPolicy();
  SecurityManager oldSecurityManager=System.getSecurityManager();
  try {
    Policy.setPolicy(new PermissivePolicy());
    System.setSecurityManager(new SecurityManager());
    doTestUnloadable();
  }
  finally {
    System.setSecurityManager(oldSecurityManager);
    Policy.setPolicy(oldPolicy);
  }
}
Program: 60211
Project: 60211
Buggy source:
/** 
 * Returns a factory that will supply instances of   {@link OutputStreamWriter}, using the given   {@link OutputStream} factory and character set.
 * @param out the factory that will be used to open output streams
 * @param charset the character set used to encode the output stream
 * @return the factory
 */
public static OutputSupplier<OutputStreamWriter> newWriterSupplier(final OutputSupplier<? extends OutputStream> out,final Charset charset){
  Preconditions.checkNotNull(out);
  Preconditions.checkNotNull(charset);
  return new OutputSupplier<OutputStreamWriter>(){
    @Override public OutputStreamWriter getOutput() throws IOException {
      return new OutputStreamWriter(out.getOutput(),charset);
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Returns a factory that will supply instances of   {@link OutputStreamWriter}, using the given   {@link OutputStream} factory and character set.
 * @param out the factory that will be used to open output streams
 * @param charset the charset used to encode the output stream; see {@link Charsets} for helpful predefined constants
 * @return the factory
 */
public static OutputSupplier<OutputStreamWriter> newWriterSupplier(final OutputSupplier<? extends OutputStream> out,final Charset charset){
  Preconditions.checkNotNull(out);
  Preconditions.checkNotNull(charset);
  return new OutputSupplier<OutputStreamWriter>(){
    @Override public OutputStreamWriter getOutput() throws IOException {
      return new OutputStreamWriter(out.getOutput(),charset);
    }
  }
;
}
Program: 60212
Project: 60212
Buggy source:
/** 
 * Returns a factory that will supply instances of   {@link InputStreamReader}, using the given   {@link InputStream} factory and character set.
 * @param in the factory that will be used to open input streams
 * @param charset the character set used to decode the input stream
 * @return the factory
 */
public static InputSupplier<InputStreamReader> newReaderSupplier(final InputSupplier<? extends InputStream> in,final Charset charset){
  Preconditions.checkNotNull(in);
  Preconditions.checkNotNull(charset);
  return new InputSupplier<InputStreamReader>(){
    @Override public InputStreamReader getInput() throws IOException {
      return new InputStreamReader(in.getInput(),charset);
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Returns a factory that will supply instances of   {@link InputStreamReader}, using the given   {@link InputStream} factory and character set.
 * @param in the factory that will be used to open input streams
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return the factory
 */
public static InputSupplier<InputStreamReader> newReaderSupplier(final InputSupplier<? extends InputStream> in,final Charset charset){
  Preconditions.checkNotNull(in);
  Preconditions.checkNotNull(charset);
  return new InputSupplier<InputStreamReader>(){
    @Override public InputStreamReader getInput() throws IOException {
      return new InputStreamReader(in.getInput(),charset);
    }
  }
;
}
Program: 60213
Project: 60213
Buggy source:
/** 
 * Returns a buffered writer that writes to a file using the given character set.
 * @param file the file to write to
 * @param charset the character set used when writing the file
 * @return the buffered writer
 */
public static BufferedWriter newWriter(File file,Charset charset) throws FileNotFoundException {
  return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),charset));
}

Fixed version (ground truth):
/** 
 * Returns a buffered writer that writes to a file using the given character set.
 * @param file the file to write to
 * @param charset the charset used to encode the output stream; see {@link Charsets} for helpful predefined constants
 * @return the buffered writer
 */
public static BufferedWriter newWriter(File file,Charset charset) throws FileNotFoundException {
  return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),charset));
}
Program: 60214
Project: 60214
Buggy source:
/** 
 * Streams lines from a   {@link File}, stopping when our callback returns false, or we have read all of the lines.
 * @param file the file to read from
 * @param charset the character set used when writing the file
 * @param callback the {@link LineProcessor} to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T>T readLines(File file,Charset charset,LineProcessor<T> callback) throws IOException {
  return CharStreams.readLines(Files.newReaderSupplier(file,charset),callback);
}

Fixed version (ground truth):
/** 
 * Streams lines from a   {@link File}, stopping when our callback returns false, or we have read all of the lines.
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @param callback the {@link LineProcessor} to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T>T readLines(File file,Charset charset,LineProcessor<T> callback) throws IOException {
  return CharStreams.readLines(Files.newReaderSupplier(file,charset),callback);
}
Program: 60215
Project: 60215
Buggy source:
/** 
 * Copies all characters from a file to an appendable object, using the given character set.
 * @param from the source file
 * @param charset the character set used when reading the file
 * @param to the appendable object
 * @throws IOException if an I/O error occurs
 */
public static void copy(File from,Charset charset,Appendable to) throws IOException {
  CharStreams.copy(newReaderSupplier(from,charset),to);
}

Fixed version (ground truth):
/** 
 * Copies all characters from a file to an appendable object, using the given character set.
 * @param from the source file
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @param to the appendable object
 * @throws IOException if an I/O error occurs
 */
public static void copy(File from,Charset charset,Appendable to) throws IOException {
  CharStreams.copy(newReaderSupplier(from,charset),to);
}
Program: 60216
Project: 60216
Buggy source:
/** 
 * Private helper method. Writes a character sequence to a file, optionally appending.
 * @param from the character sequence to append
 * @param to the destination file
 * @param charset the character set used when writing the file
 * @param append true to append, false to overwrite
 * @throws IOException if an I/O error occurs
 */
private static void write(CharSequence from,File to,Charset charset,boolean append) throws IOException {
  CharStreams.write(from,newWriterSupplier(to,charset,append));
}

Fixed version (ground truth):
/** 
 * Private helper method. Writes a character sequence to a file, optionally appending.
 * @param from the character sequence to append
 * @param to the destination file
 * @param charset the charset used to encode the output stream; see {@link Charsets} for helpful predefined constants
 * @param append true to append, false to overwrite
 * @throws IOException if an I/O error occurs
 */
private static void write(CharSequence from,File to,Charset charset,boolean append) throws IOException {
  CharStreams.write(from,newWriterSupplier(to,charset,append));
}
Program: 60217
Project: 60217
Buggy source:
/** 
 * Returns a buffered reader that reads from a file using the given character set.
 * @param file the file to read from
 * @param charset the character set used when writing the file
 * @return the buffered reader
 */
public static BufferedReader newReader(File file,Charset charset) throws FileNotFoundException {
  return new BufferedReader(new InputStreamReader(new FileInputStream(file),charset));
}

Fixed version (ground truth):
/** 
 * Returns a buffered reader that reads from a file using the given character set.
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return the buffered reader
 */
public static BufferedReader newReader(File file,Charset charset) throws FileNotFoundException {
  return new BufferedReader(new InputStreamReader(new FileInputStream(file),charset));
}
Program: 60218
Project: 60218
Buggy source:
/** 
 * Reads the first line from a file. The line does not include line-termination characters, but does include other leading and trailing whitespace.
 * @param file the file to read from
 * @param charset the character set used when writing the file
 * @return the first line, or null if the file is empty
 * @throws IOException if an I/O error occurs
 */
public static String readFirstLine(File file,Charset charset) throws IOException {
  return CharStreams.readFirstLine(Files.newReaderSupplier(file,charset));
}

Fixed version (ground truth):
/** 
 * Reads the first line from a file. The line does not include line-termination characters, but does include other leading and trailing whitespace.
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return the first line, or null if the file is empty
 * @throws IOException if an I/O error occurs
 */
public static String readFirstLine(File file,Charset charset) throws IOException {
  return CharStreams.readFirstLine(Files.newReaderSupplier(file,charset));
}
Program: 60219
Project: 60219
Buggy source:
/** 
 * Returns a factory that will supply instances of   {@link OutputStreamWriter}that write to or append to a file using the given character set.
 * @param file the file to write to
 * @param charset the character set used when writing the file
 * @param append if true, the encoded characters will be appended to the file;otherwise the file is overwritten
 * @return the factory
 */
public static OutputSupplier<OutputStreamWriter> newWriterSupplier(File file,Charset charset,boolean append){
  return CharStreams.newWriterSupplier(newOutputStreamSupplier(file,append),charset);
}

Fixed version (ground truth):
/** 
 * Returns a factory that will supply instances of   {@link OutputStreamWriter}that write to or append to a file using the given character set.
 * @param file the file to write to
 * @param charset the charset used to encode the output stream; see {@link Charsets} for helpful predefined constants
 * @param append if true, the encoded characters will be appended to the file;otherwise the file is overwritten
 * @return the factory
 */
public static OutputSupplier<OutputStreamWriter> newWriterSupplier(File file,Charset charset,boolean append){
  return CharStreams.newWriterSupplier(newOutputStreamSupplier(file,append),charset);
}
Program: 60220
Project: 60220
Buggy source:
/** 
 * Reads all characters from a file into a   {@link String}, using the given character set.
 * @param file the file to read from
 * @param charset the character set used when reading the file
 * @return a string containing all the characters from the file
 * @throws IOException if an I/O error occurs
 */
public static String toString(File file,Charset charset) throws IOException {
  return new String(toByteArray(file),charset.name());
}

Fixed version (ground truth):
/** 
 * Reads all characters from a file into a   {@link String}, using the given character set.
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return a string containing all the characters from the file
 * @throws IOException if an I/O error occurs
 */
public static String toString(File file,Charset charset) throws IOException {
  return new String(toByteArray(file),charset.name());
}
Program: 60221
Project: 60221
Buggy source:
/** 
 * Returns a factory that will supply instances of  {@link InputStreamReader} that read a file using the given character set.
 * @param file the file to read from
 * @param charset the character set used when reading the file
 * @return the factory
 */
public static InputSupplier<InputStreamReader> newReaderSupplier(File file,Charset charset){
  return CharStreams.newReaderSupplier(newInputStreamSupplier(file),charset);
}

Fixed version (ground truth):
/** 
 * Returns a factory that will supply instances of  {@link InputStreamReader} that read a file using the given character set.
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return the factory
 */
public static InputSupplier<InputStreamReader> newReaderSupplier(File file,Charset charset){
  return CharStreams.newReaderSupplier(newInputStreamSupplier(file),charset);
}
Program: 60222
Project: 60222
Buggy source:
/** 
 * Appends a character sequence (such as a string) to a file using the given character set.
 * @param from the character sequence to append
 * @param to the destination file
 * @param charset the character set used when writing the file
 * @throws IOException if an I/O error occurs
 */
public static void append(CharSequence from,File to,Charset charset) throws IOException {
  write(from,to,charset,true);
}

Fixed version (ground truth):
/** 
 * Appends a character sequence (such as a string) to a file using the given character set.
 * @param from the character sequence to append
 * @param to the destination file
 * @param charset the charset used to encode the output stream; see {@link Charsets} for helpful predefined constants
 * @throws IOException if an I/O error occurs
 */
public static void append(CharSequence from,File to,Charset charset) throws IOException {
  write(from,to,charset,true);
}
Program: 60223
Project: 60223
Buggy source:
/** 
 * Reads all of the lines from a URL. The lines do not include line-termination characters, but do include other leading and trailing whitespace.
 * @param url the URL to read from
 * @param charset the character set used when writing the file
 * @return a mutable {@link List} containing all the lines
 * @throws IOException if an I/O error occurs
 */
public static List<String> readLines(URL url,Charset charset) throws IOException {
  return CharStreams.readLines(newReaderSupplier(url,charset));
}

Fixed version (ground truth):
/** 
 * Reads all of the lines from a URL. The lines do not include line-termination characters, but do include other leading and trailing whitespace.
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return a mutable {@link List} containing all the lines
 * @throws IOException if an I/O error occurs
 */
public static List<String> readLines(URL url,Charset charset) throws IOException {
  return CharStreams.readLines(newReaderSupplier(url,charset));
}
Program: 60224
Project: 60224
Buggy source:
/** 
 * Reads all characters from a URL into a   {@link String}, using the given character set.
 * @param url the URL to read from
 * @param charset the character set used when reading the URL
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url,Charset charset) throws IOException {
  return CharStreams.toString(newReaderSupplier(url,charset));
}

Fixed version (ground truth):
/** 
 * Reads all characters from a URL into a   {@link String}, using the given character set.
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url,Charset charset) throws IOException {
  return CharStreams.toString(newReaderSupplier(url,charset));
}
Program: 60225
Project: 60225
Buggy source:
/** 
 * Returns a factory that will supply instances of  {@link InputStreamReader} that read a URL using the given character set.
 * @param url the URL to read from
 * @param charset the character set used when reading the URL contents
 * @return the factory
 */
public static InputSupplier<InputStreamReader> newReaderSupplier(URL url,Charset charset){
  return CharStreams.newReaderSupplier(newInputStreamSupplier(url),charset);
}

Fixed version (ground truth):
/** 
 * Returns a factory that will supply instances of  {@link InputStreamReader} that read a URL using the given character set.
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful predefined constants
 * @return the factory
 */
public static InputSupplier<InputStreamReader> newReaderSupplier(URL url,Charset charset){
  return CharStreams.newReaderSupplier(newInputStreamSupplier(url),charset);
}
Program: 60226
Project: 60226
Buggy source:
/** 
 * Associates   {@code value} with {@code key} in this cache. If the cache previously contained avalue associated with  {@code key}, the old value is replaced by   {@code value}. <p>Prefer   {@link #get(K,Callable)} when using the conventional "if cached, return; otherwisecreate, cache and return" pattern.
 * @since 11.0
 */
void put(K key,V value);

Fixed version (ground truth):
/** 
 * Associates   {@code value} with {@code key} in this cache. If the cache previously contained avalue associated with  {@code key}, the old value is replaced by   {@code value}. <p>Prefer   {@link #get(Object,Callable)} when using the conventional "if cached, return;otherwise create, cache and return" pattern.
 * @since 11.0
 */
void put(K key,V value);