nus-yam/ex-repair huggingface dataset:
Program: 60139
Project: 60139
Buggy source:
@Override public final ListenableFuture<State> start(){
  lock.lock();
  try {
    if (snapshot.state == State.NEW) {
      snapshot=new StateSnapshot(State.STARTING);
      starting();
      doStart();
    }
  }
 catch (  Throwable startupFailure) {
    notifyFailed(startupFailure);
  }
 finally {
    lock.unlock();
    executeListeners();
  }
  return startup;
}

Fixed version (ground truth):
@Override public final ListenableFuture<State> start(){
  lock.lock();
  try {
    if (state() == State.NEW) {
      snapshot=new StateSnapshot(State.STARTING);
      starting();
      doStart();
    }
  }
 catch (  Throwable startupFailure) {
    notifyFailed(startupFailure);
  }
 finally {
    lock.unlock();
    executeListeners();
  }
  return startup;
}
Program: 60140
Project: 60140
Buggy source:
/** 
 * Implementing classes should invoke this method once their service has stopped. It will cause the service to transition from   {@link State#STOPPING} to {@link State#TERMINATED}.
 * @throws IllegalStateException if the service is neither {@link State#STOPPING} nor{@link State#RUNNING}.
 */
protected final void notifyStopped(){
  lock.lock();
  try {
    if (snapshot.state != State.STOPPING && snapshot.state != State.RUNNING) {
      IllegalStateException failure=new IllegalStateException("String_Node_Str" + snapshot.state);
      notifyFailed(failure);
      throw failure;
    }
    State previous=snapshot.state;
    snapshot=new StateSnapshot(State.TERMINATED);
    terminated(previous);
  }
  finally {
    lock.unlock();
    executeListeners();
  }
}

Fixed version (ground truth):
/** 
 * Implementing classes should invoke this method once their service has stopped. It will cause the service to transition from   {@link State#STOPPING} to {@link State#TERMINATED}.
 * @throws IllegalStateException if the service is neither {@link State#STOPPING} nor{@link State#RUNNING}.
 */
protected final void notifyStopped(){
  lock.lock();
  try {
    State previous=snapshot.state;
    if (previous != State.STOPPING && previous != State.RUNNING) {
      IllegalStateException failure=new IllegalStateException("String_Node_Str" + previous);
      notifyFailed(failure);
      throw failure;
    }
    snapshot=new StateSnapshot(State.TERMINATED);
    terminated(previous);
  }
  finally {
    lock.unlock();
    executeListeners();
  }
}
Program: 60141
Project: 60141
Buggy source:
@Override public final ListenableFuture<State> stop(){
  lock.lock();
  try {
switch (snapshot.state) {
case NEW:
      snapshot=new StateSnapshot(State.TERMINATED);
    terminated(State.NEW);
  break;
case STARTING:
snapshot=new StateSnapshot(State.STARTING,true,null);
stopping(State.STARTING);
break;
case RUNNING:
snapshot=new StateSnapshot(State.STOPPING);
stopping(State.RUNNING);
doStop();
break;
case STOPPING:
case TERMINATED:
case FAILED:
break;
default :
throw new AssertionError("String_Node_Str" + snapshot.state);
}
}
 catch (Throwable shutdownFailure) {
notifyFailed(shutdownFailure);
}
 finally {
lock.unlock();
executeListeners();
}
return shutdown;
}

Fixed version (ground truth):
@Override public final ListenableFuture<State> stop(){
  lock.lock();
  try {
    State previous=state();
switch (previous) {
case NEW:
      snapshot=new StateSnapshot(State.TERMINATED);
    terminated(State.NEW);
  break;
case STARTING:
snapshot=new StateSnapshot(State.STARTING,true,null);
stopping(State.STARTING);
break;
case RUNNING:
snapshot=new StateSnapshot(State.STOPPING);
stopping(State.RUNNING);
doStop();
break;
case STOPPING:
case TERMINATED:
case FAILED:
break;
default :
throw new AssertionError("String_Node_Str" + previous);
}
}
 catch (Throwable shutdownFailure) {
notifyFailed(shutdownFailure);
}
 finally {
lock.unlock();
executeListeners();
}
return shutdown;
}
Program: 60142
Project: 60142
Buggy source:
/** 
 * Invoke this method to transition the service to the   {@link State#FAILED}. The service will <b>not be stopped</b> if it is running. Invoke this method when a service has failed critically or otherwise cannot be started nor stopped.
 */
protected final void notifyFailed(Throwable cause){
  checkNotNull(cause);
  lock.lock();
  try {
switch (snapshot.state) {
case NEW:
case TERMINATED:
      throw new IllegalStateException("String_Node_Str" + snapshot.state,cause);
case RUNNING:
case STARTING:
case STOPPING:
    State previous=snapshot.state;
  snapshot=new StateSnapshot(State.FAILED,false,cause);
failed(previous,cause);
break;
case FAILED:
break;
default :
throw new AssertionError("String_Node_Str" + snapshot.state);
}
}
  finally {
lock.unlock();
executeListeners();
}
}

Fixed version (ground truth):
/** 
 * Invoke this method to transition the service to the   {@link State#FAILED}. The service will <b>not be stopped</b> if it is running. Invoke this method when a service has failed critically or otherwise cannot be started nor stopped.
 */
protected final void notifyFailed(Throwable cause){
  checkNotNull(cause);
  lock.lock();
  try {
    State previous=state();
switch (previous) {
case NEW:
case TERMINATED:
      throw new IllegalStateException("String_Node_Str" + previous,cause);
case RUNNING:
case STARTING:
case STOPPING:
    snapshot=new StateSnapshot(State.FAILED,false,cause);
  failed(previous,cause);
break;
case FAILED:
break;
default :
throw new AssertionError("String_Node_Str" + previous);
}
}
  finally {
lock.unlock();
executeListeners();
}
}
Program: 60143
Project: 60143
Buggy source:
@Override public T next(){
  if (!hasNext()) {
    throw new NoSuchElementException();
  }
  try {
    return iterator.next();
  }
  finally {
    atStart=false;
  }
}

Fixed version (ground truth):
@Override public T next(){
  T result=iterator.next();
  atStart=false;
  return result;
}
Program: 60145
Project: 60145
Buggy source:
/** 
 * Returns the last element of   {@code iterable} or {@code defaultValue} ifthe iterable is empty.
 * @param defaultValue the value to return if {@code iterable} is empty
 * @return the last element of {@code iterable} or the default value
 * @since 3.0
 */
@Nullable public static <T>T getLast(Iterable<? extends T> iterable,@Nullable T defaultValue){
  if (iterable instanceof Collection) {
    Collection<? extends T> c=Collections2.cast(iterable);
    if (c.isEmpty()) {
      return defaultValue;
    }
 else     if (iterable instanceof List) {
      List<? extends T> list=Lists.cast(iterable);
      return getLastInNonemptyList(list);
    }
  }
  return Iterators.getLast(iterable.iterator(),defaultValue);
}

Fixed version (ground truth):
/** 
 * Returns the last element of   {@code iterable} or {@code defaultValue} ifthe iterable is empty.
 * @param defaultValue the value to return if {@code iterable} is empty
 * @return the last element of {@code iterable} or the default value
 * @since 3.0
 */
@Nullable public static <T>T getLast(Iterable<? extends T> iterable,@Nullable T defaultValue){
  if (iterable instanceof Collection) {
    Collection<? extends T> c=Collections2.cast(iterable);
    if (c.isEmpty()) {
      return defaultValue;
    }
 else     if (iterable instanceof List) {
      return getLastInNonemptyList(Lists.cast(iterable));
    }
  }
  return Iterators.getLast(iterable.iterator(),defaultValue);
}
Program: 60146
Project: 60146
Buggy source:
@Override public void remove(){
  if (atStart) {
    throw new IllegalStateException();
  }
  iterator.remove();
}

Fixed version (ground truth):
@Override public void remove(){
  Iterators.checkRemove(!atStart);
  iterator.remove();
}
Program: 60147
Project: 60147
Buggy source:
/** 
 * Adds all elements in   {@code iterable} to {@code collection}.
 * @return {@code true} if {@code collection} was modified as a result of thisoperation.
 */
public static <T>boolean addAll(Collection<T> addTo,Iterable<? extends T> elementsToAdd){
  if (elementsToAdd instanceof Collection) {
    Collection<? extends T> c=Collections2.cast(elementsToAdd);
    return addTo.addAll(c);
  }
  return Iterators.addAll(addTo,elementsToAdd.iterator());
}

Fixed version (ground truth):
/** 
 * Adds all elements in   {@code iterable} to {@code collection}.
 * @return {@code true} if {@code collection} was modified as a result of thisoperation.
 */
public static <T>boolean addAll(Collection<T> addTo,Iterable<? extends T> elementsToAdd){
  if (elementsToAdd instanceof Collection) {
    Collection<? extends T> c=Collections2.cast(elementsToAdd);
    return addTo.addAll(c);
  }
  return Iterators.addAll(addTo,checkNotNull(elementsToAdd).iterator());
}
Program: 60148
Project: 60148
Buggy source:
/** 
 * Combines multiple iterators into a single iterator. The returned iterator iterates across the elements of each iterator in   {@code inputs}. The input iterators are not polled until necessary. <p>The returned iterator supports   {@code remove()} when the correspondinginput iterator supports it. The methods of the returned iterator may throw {@code NullPointerException} if any of the input iterators is null.<p><b>Note:</b> the current implementation is not suitable for nested concatenated iterators, i.e. the following should be avoided when in a loop: {@code iterator = Iterators.concat(iterator, suffix);}, since iteration over the resulting iterator has a cubic complexity to the depth of the nesting.
 */
public static <T>Iterator<T> concat(final Iterator<? extends Iterator<? extends T>> inputs){
  checkNotNull(inputs);
  return new Iterator<T>(){
    Iterator<? extends T> current=emptyIterator();
    Iterator<? extends T> removeFrom;
    @Override public boolean hasNext(){
      boolean currentHasNext;
      while (!(currentHasNext=checkNotNull(current).hasNext()) && inputs.hasNext()) {
        current=inputs.next();
      }
      return currentHasNext;
    }
    @Override public T next(){
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      removeFrom=current;
      return current.next();
    }
    @Override public void remove(){
      checkState(removeFrom != null,"String_Node_Str");
      removeFrom.remove();
      removeFrom=null;
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Combines multiple iterators into a single iterator. The returned iterator iterates across the elements of each iterator in   {@code inputs}. The input iterators are not polled until necessary. <p>The returned iterator supports   {@code remove()} when the correspondinginput iterator supports it. The methods of the returned iterator may throw {@code NullPointerException} if any of the input iterators is null.<p><b>Note:</b> the current implementation is not suitable for nested concatenated iterators, i.e. the following should be avoided when in a loop: {@code iterator = Iterators.concat(iterator, suffix);}, since iteration over the resulting iterator has a cubic complexity to the depth of the nesting.
 */
public static <T>Iterator<T> concat(final Iterator<? extends Iterator<? extends T>> inputs){
  checkNotNull(inputs);
  return new Iterator<T>(){
    Iterator<? extends T> current=emptyIterator();
    Iterator<? extends T> removeFrom;
    @Override public boolean hasNext(){
      boolean currentHasNext;
      while (!(currentHasNext=checkNotNull(current).hasNext()) && inputs.hasNext()) {
        current=inputs.next();
      }
      return currentHasNext;
    }
    @Override public T next(){
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      removeFrom=current;
      return current.next();
    }
    @Override public void remove(){
      checkRemove(removeFrom != null);
      removeFrom.remove();
      removeFrom=null;
    }
  }
;
}
Program: 60149
Project: 60149
Buggy source:
/** 
 * Adds all elements in   {@code iterator} to {@code collection}. The iterator will be left exhausted: its   {@code hasNext()} method will return{@code false}.
 * @return {@code true} if {@code collection} was modified as a result of thisoperation
 */
public static <T>boolean addAll(Collection<T> addTo,Iterator<? extends T> iterator){
  checkNotNull(addTo);
  boolean wasModified=false;
  while (iterator.hasNext()) {
    wasModified|=addTo.add(iterator.next());
  }
  return wasModified;
}

Fixed version (ground truth):
/** 
 * Adds all elements in   {@code iterator} to {@code collection}. The iterator will be left exhausted: its   {@code hasNext()} method will return{@code false}.
 * @return {@code true} if {@code collection} was modified as a result of thisoperation
 */
public static <T>boolean addAll(Collection<T> addTo,Iterator<? extends T> iterator){
  checkNotNull(addTo);
  checkNotNull(iterator);
  boolean wasModified=false;
  while (iterator.hasNext()) {
    wasModified|=addTo.add(iterator.next());
  }
  return wasModified;
}
Program: 60150
Project: 60150
Buggy source:
/** 
 * Creates a   {@code LinkedList} instance containing the given elements.
 * @param elements the elements that the list should contain, in order
 * @return a new {@code LinkedList} containing those elements
 */
@GwtCompatible(serializable=true) public static <E>LinkedList<E> newLinkedList(Iterable<? extends E> elements){
  LinkedList<E> list=newLinkedList();
  for (  E element : elements) {
    list.add(element);
  }
  return list;
}

Fixed version (ground truth):
/** 
 * Creates a   {@code LinkedList} instance containing the given elements.
 * @param elements the elements that the list should contain, in order
 * @return a new {@code LinkedList} containing those elements
 */
@GwtCompatible(serializable=true) public static <E>LinkedList<E> newLinkedList(Iterable<? extends E> elements){
  LinkedList<E> list=newLinkedList();
  Iterables.addAll(list,elements);
  return list;
}
Program: 60151
Project: 60151
Buggy source:
/** 
 * Creates a <i>mutable</i>   {@code ArrayList} instance containing the givenelements. <p><b>Note:</b> if mutability is not required and the elements are non-null, use  {@link ImmutableList#copyOf(Iterator)} instead.
 * @param elements the elements that the list should contain, in order
 * @return a new {@code ArrayList} containing those elements
 */
@GwtCompatible(serializable=true) public static <E>ArrayList<E> newArrayList(Iterator<? extends E> elements){
  checkNotNull(elements);
  ArrayList<E> list=newArrayList();
  while (elements.hasNext()) {
    list.add(elements.next());
  }
  return list;
}

Fixed version (ground truth):
/** 
 * Creates a <i>mutable</i>   {@code ArrayList} instance containing the givenelements. <p><b>Note:</b> if mutability is not required and the elements are non-null, use  {@link ImmutableList#copyOf(Iterator)} instead.
 * @param elements the elements that the list should contain, in order
 * @return a new {@code ArrayList} containing those elements
 */
@GwtCompatible(serializable=true) public static <E>ArrayList<E> newArrayList(Iterator<? extends E> elements){
  ArrayList<E> list=newArrayList();
  Iterators.addAll(list,elements);
  return list;
}
Program: 60152
Project: 60152
Buggy source:
/** 
 * Creates a <i>mutable</i>   {@code LinkedHashSet} instance containing thegiven elements in order. <p><b>Note:</b> if mutability is not required and the elements are non-null, use  {@link ImmutableSet#copyOf(Iterable)} instead.
 * @param elements the elements that the set should contain, in order
 * @return a new {@code LinkedHashSet} containing those elements (minusduplicates)
 */
public static <E>LinkedHashSet<E> newLinkedHashSet(Iterable<? extends E> elements){
  if (elements instanceof Collection) {
    return new LinkedHashSet<E>(Collections2.cast(elements));
  }
  LinkedHashSet<E> set=newLinkedHashSet();
  for (  E element : elements) {
    set.add(element);
  }
  return set;
}

Fixed version (ground truth):
/** 
 * Creates a <i>mutable</i>   {@code LinkedHashSet} instance containing thegiven elements in order. <p><b>Note:</b> if mutability is not required and the elements are non-null, use  {@link ImmutableSet#copyOf(Iterable)} instead.
 * @param elements the elements that the set should contain, in order
 * @return a new {@code LinkedHashSet} containing those elements (minusduplicates)
 */
public static <E>LinkedHashSet<E> newLinkedHashSet(Iterable<? extends E> elements){
  if (elements instanceof Collection) {
    return new LinkedHashSet<E>(Collections2.cast(elements));
  }
  LinkedHashSet<E> set=newLinkedHashSet();
  Iterables.addAll(set,elements);
  return set;
}
Program: 60153
Project: 60153
Buggy source:
/** 
 * Creates a <i>mutable</i>   {@code HashSet} instance containing the givenelements in unspecified order. <p><b>Note:</b> if mutability is not required and the elements are non-null, use  {@link ImmutableSet#copyOf(Iterable)} instead.<p><b>Note:</b> if  {@code E} is an {@link Enum} type, you should create an{@link EnumSet} instead.
 * @param elements the elements that the set should contain
 * @return a new {@code HashSet} containing those elements (minus duplicates)
 */
public static <E>HashSet<E> newHashSet(Iterator<? extends E> elements){
  HashSet<E> set=newHashSet();
  while (elements.hasNext()) {
    set.add(elements.next());
  }
  return set;
}

Fixed version (ground truth):
/** 
 * Creates a <i>mutable</i>   {@code HashSet} instance containing the givenelements in unspecified order. <p><b>Note:</b> if mutability is not required and the elements are non-null, use  {@link ImmutableSet#copyOf(Iterable)} instead.<p><b>Note:</b> if  {@code E} is an {@link Enum} type, you should create an{@link EnumSet} instead.
 * @param elements the elements that the set should contain
 * @return a new {@code HashSet} containing those elements (minus duplicates)
 */
public static <E>HashSet<E> newHashSet(Iterator<? extends E> elements){
  HashSet<E> set=newHashSet();
  Iterators.addAll(set,elements);
  return set;
}
Program: 60154
Project: 60154
Buggy source:
static boolean removeAllImpl(Set<?> set,Collection<?> collection){
  checkNotNull(collection);
  if (collection instanceof Multiset) {
    collection=((Multiset<?>)collection).elementSet();
  }
  if (collection instanceof Set && collection.size() > set.size()) {
    Iterator<?> setIterator=set.iterator();
    boolean changed=false;
    while (setIterator.hasNext()) {
      if (collection.contains(setIterator.next())) {
        changed=true;
        setIterator.remove();
      }
    }
    return changed;
  }
 else {
    return removeAllImpl(set,collection.iterator());
  }
}

Fixed version (ground truth):
static boolean removeAllImpl(Set<?> set,Collection<?> collection){
  checkNotNull(collection);
  if (collection instanceof Multiset) {
    collection=((Multiset<?>)collection).elementSet();
  }
  if (collection instanceof Set && collection.size() > set.size()) {
    return Iterators.removeAll(set.iterator(),collection);
  }
 else {
    return removeAllImpl(set,collection.iterator());
  }
}
Program: 60155
Project: 60155
Buggy source:
public sun.misc.Unsafe run() throws Exception {
  java.lang.reflect.Field f;
  try {
    f=sun.misc.Unsafe.class.getDeclaredField("String_Node_Str");
  }
 catch (  NoSuchFieldException e) {
    f=sun.misc.Unsafe.class.getDeclaredField("String_Node_Str");
  }
  f.setAccessible(true);
  return (sun.misc.Unsafe)f.get(null);
}

Fixed version (ground truth):
public sun.misc.Unsafe run() throws Exception {
  Class<sun.misc.Unsafe> k=sun.misc.Unsafe.class;
  for (  java.lang.reflect.Field f : k.getDeclaredFields()) {
    f.setAccessible(true);
    Object x=f.get(null);
    if (k.isInstance(x))     return k.cast(x);
  }
  throw new NoSuchFieldError("String_Node_Str");
}
Program: 60156
Project: 60156
Buggy source:
/** 
 * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package. Replace with a simple call to Unsafe.getUnsafe when integrating into a jdk.
 * @return a sun.misc.Unsafe
 */
private static sun.misc.Unsafe getUnsafe(){
  try {
    return sun.misc.Unsafe.getUnsafe();
  }
 catch (  SecurityException se) {
    try {
      return java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>(){
        public sun.misc.Unsafe run() throws Exception {
          java.lang.reflect.Field f;
          try {
            f=sun.misc.Unsafe.class.getDeclaredField("String_Node_Str");
          }
 catch (          NoSuchFieldException e) {
            f=sun.misc.Unsafe.class.getDeclaredField("String_Node_Str");
          }
          f.setAccessible(true);
          return (sun.misc.Unsafe)f.get(null);
        }
      }
);
    }
 catch (    java.security.PrivilegedActionException e) {
      throw new RuntimeException("String_Node_Str",e.getCause());
    }
  }
}

Fixed version (ground truth):
/** 
 * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package. Replace with a simple call to Unsafe.getUnsafe when integrating into a jdk.
 * @return a sun.misc.Unsafe
 */
private static sun.misc.Unsafe getUnsafe(){
  try {
    return sun.misc.Unsafe.getUnsafe();
  }
 catch (  SecurityException tryReflectionInstead) {
  }
  try {
    return java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>(){
      public sun.misc.Unsafe run() throws Exception {
        Class<sun.misc.Unsafe> k=sun.misc.Unsafe.class;
        for (        java.lang.reflect.Field f : k.getDeclaredFields()) {
          f.setAccessible(true);
          Object x=f.get(null);
          if (k.isInstance(x))           return k.cast(x);
        }
        throw new NoSuchFieldError("String_Node_Str");
      }
    }
);
  }
 catch (  java.security.PrivilegedActionException e) {
    throw new RuntimeException("String_Node_Str",e.getCause());
  }
}
Program: 60157
Project: 60157
Buggy source:
@Override public Object run(){
  try {
    Field f=Unsafe.class.getDeclaredField("String_Node_Str");
    f.setAccessible(true);
    return f.get(null);
  }
 catch (  NoSuchFieldException e) {
    throw new Error();
  }
catch (  IllegalAccessException e) {
    throw new Error();
  }
}

Fixed version (ground truth):
public sun.misc.Unsafe run() throws Exception {
  Class<sun.misc.Unsafe> k=sun.misc.Unsafe.class;
  for (  java.lang.reflect.Field f : k.getDeclaredFields()) {
    f.setAccessible(true);
    Object x=f.get(null);
    if (k.isInstance(x))     return k.cast(x);
  }
  throw new NoSuchFieldError("String_Node_Str");
}
Program: 60158
Project: 60158
Buggy source:
@Override public V get(@Nullable Object key){
  if (key instanceof Range) {
    Range<?> range=(Range<?>)key;
    RangeMapEntry<K,V> rangeMapEntry=entriesByLowerBound.get(range.lowerBound);
    if (rangeMapEntry.getKey().equals(range)) {
      return rangeMapEntry.getValue();
    }
  }
  return null;
}

Fixed version (ground truth):
@Override public V get(@Nullable Object key){
  if (key instanceof Range) {
    Range<?> range=(Range<?>)key;
    RangeMapEntry<K,V> rangeMapEntry=entriesByLowerBound.get(range.lowerBound);
    if (rangeMapEntry != null && rangeMapEntry.getKey().equals(range)) {
      return rangeMapEntry.getValue();
    }
  }
  return null;
}
Program: 60159
Project: 60159
Buggy source:
public void testCancel_notDoneNoInterrupt(){
  InterruptibleFuture future=new InterruptibleFuture();
  assertTrue(future.cancel(false));
  assertTrue(future.isCancelled());
  assertTrue(future.isDone());
  assertFalse(future.wasInterrupted());
  assertFalse(future.interruptTaskWasCalled);
}

Fixed version (ground truth):
public void testCancel_notDoneNoInterrupt() throws Exception {
  InterruptibleFuture future=new InterruptibleFuture();
  assertTrue(future.cancel(false));
  assertTrue(future.isCancelled());
  assertTrue(future.isDone());
  assertFalse(future.wasInterrupted());
  assertFalse(future.interruptTaskWasCalled);
  try {
    future.get();
    fail("String_Node_Str");
  }
 catch (  CancellationException e) {
    assertNotNull(e.getCause());
  }
}
Program: 60160
Project: 60160
Buggy source:
public void testCancel_notDoneInterrupt(){
  InterruptibleFuture future=new InterruptibleFuture();
  assertTrue(future.cancel(true));
  assertTrue(future.isCancelled());
  assertTrue(future.isDone());
  assertTrue(future.wasInterrupted());
  assertTrue(future.interruptTaskWasCalled);
}

Fixed version (ground truth):
public void testCancel_notDoneInterrupt() throws Exception {
  InterruptibleFuture future=new InterruptibleFuture();
  assertTrue(future.cancel(true));
  assertTrue(future.isCancelled());
  assertTrue(future.isDone());
  assertTrue(future.wasInterrupted());
  assertTrue(future.interruptTaskWasCalled);
  try {
    future.get();
    fail("String_Node_Str");
  }
 catch (  CancellationException e) {
    assertNotNull(e.getCause());
  }
}
Program: 60161
Project: 60161
Buggy source:
@Override protected void interruptTask(){
  interruptTaskWasCalled=true;
}

Fixed version (ground truth):
@Override protected void interruptTask(){
  assertFalse(interruptTaskWasCalled);
  interruptTaskWasCalled=true;
}
Program: 60162
Project: 60162
Buggy source:
public void testCancel_done(){
  AbstractFuture<String> future=new AbstractFuture<String>(){
{
      set("String_Node_Str");
    }
  }
;
  assertFalse(future.cancel(true));
  assertFalse(future.isCancelled());
  assertTrue(future.isDone());
}

Fixed version (ground truth):
public void testCancel_done() throws Exception {
  AbstractFuture<String> future=new AbstractFuture<String>(){
{
      set("String_Node_Str");
    }
  }
;
  assertFalse(future.cancel(true));
  assertFalse(future.isCancelled());
  assertTrue(future.isDone());
}
Program: 60163
Project: 60163
Buggy source:
/** 
 * Implementation of completing a task.  Either   {@code v} or {@code t} willbe set but not both.  The  {@code finalState} is the state to change tofrom  {@link #RUNNING}.  If the state is not in the RUNNING state we return   {@code false} after waiting for the state to be set to a validfinal state ( {@link #COMPLETED},   {@link #CANCELLED}, or   {@link #INTERRUPTED}).
 * @param v the value to set as the result of the computation.
 * @param t the exception to set as the result of the computation.
 * @param finalState the state to transition to.
 */
private boolean complete(@Nullable V v,@Nullable Throwable t,int finalState){
  boolean doCompletion=compareAndSetState(RUNNING,COMPLETING);
  if (doCompletion) {
    this.value=v;
    this.exception=isCancelled() ? new CancellationException("String_Node_Str") : t;
    releaseShared(finalState);
  }
 else   if (getState() == COMPLETING) {
    acquireShared(-1);
  }
  return doCompletion;
}

Fixed version (ground truth):
/** 
 * Implementation of completing a task.  Either   {@code v} or {@code t} willbe set but not both.  The  {@code finalState} is the state to change tofrom  {@link #RUNNING}.  If the state is not in the RUNNING state we return   {@code false} after waiting for the state to be set to a validfinal state ( {@link #COMPLETED},   {@link #CANCELLED}, or   {@link #INTERRUPTED}).
 * @param v the value to set as the result of the computation.
 * @param t the exception to set as the result of the computation.
 * @param finalState the state to transition to.
 */
private boolean complete(@Nullable V v,@Nullable Throwable t,int finalState){
  boolean doCompletion=compareAndSetState(RUNNING,COMPLETING);
  if (doCompletion) {
    this.value=v;
    this.exception=((finalState & (CANCELLED | INTERRUPTED)) != 0) ? new CancellationException("String_Node_Str") : t;
    releaseShared(finalState);
  }
 else   if (getState() == COMPLETING) {
    acquireShared(-1);
  }
  return doCompletion;
}
Program: 60164
Project: 60164
Buggy source:
public void testGenericInterface(){
  Type fType=Function.class.getTypeParameters()[0];
  assertEquals(Integer.class,TypeToken.of(IntegerStringFunction.class).resolveType(fType).getRawType());
  Type predicateParameterType=Predicate.class.getTypeParameters()[0];
  assertEquals(new TypeToken<List<String>>(){
  }
.getType(),TypeToken.of(IntegerStringFunction.class).resolveType(predicateParameterType).getType());
}

Fixed version (ground truth):
public void testGenericInterface(){
  Type fType=Supplier.class.getTypeParameters()[0];
  assertEquals(Integer.class,TypeToken.of(IntegerStringFunction.class).resolveType(fType).getRawType());
  Type predicateParameterType=Predicate.class.getTypeParameters()[0];
  assertEquals(new TypeToken<List<String>>(){
  }
.getType(),TypeToken.of(IntegerStringFunction.class).resolveType(predicateParameterType).getType());
}
Program: 60165
Project: 60165
Buggy source:
public void testParse_multipleKeys(){
  CacheBuilderSpec spec=parse("String_Node_Str" + "String_Node_Str");
  assertEquals(10,spec.initialCapacity.intValue());
  assertEquals(20,spec.maximumSize.intValue());
  assertNull(spec.maximumWeight);
  assertEquals(30,spec.concurrencyLevel.intValue());
  assertEquals(Strength.WEAK,spec.keyStrength);
  assertEquals(Strength.WEAK,spec.valueStrength);
  assertEquals(TimeUnit.HOURS,spec.writeExpirationTimeUnit);
  assertEquals(TimeUnit.MINUTES,spec.accessExpirationTimeUnit);
  assertEquals(1L,spec.writeExpirationDuration);
  assertEquals(10L,spec.accessExpirationDuration);
  CacheBuilder expected=CacheBuilder.newBuilder().initialCapacity(10).maximumSize(20).concurrencyLevel(30).weakKeys().weakValues().expireAfterAccess(10L,TimeUnit.MINUTES);
  assertCacheBuilderEquivalence(expected,CacheBuilder.from(spec));
}

Fixed version (ground truth):
public void testParse_multipleKeys(){
  CacheBuilderSpec spec=parse("String_Node_Str" + "String_Node_Str");
  assertEquals(10,spec.initialCapacity.intValue());
  assertEquals(20,spec.maximumSize.intValue());
  assertNull(spec.maximumWeight);
  assertEquals(30,spec.concurrencyLevel.intValue());
  assertEquals(Strength.WEAK,spec.keyStrength);
  assertEquals(Strength.WEAK,spec.valueStrength);
  assertEquals(TimeUnit.HOURS,spec.writeExpirationTimeUnit);
  assertEquals(TimeUnit.MINUTES,spec.accessExpirationTimeUnit);
  assertEquals(1L,spec.writeExpirationDuration);
  assertEquals(10L,spec.accessExpirationDuration);
  CacheBuilder expected=CacheBuilder.newBuilder().initialCapacity(10).maximumSize(20).concurrencyLevel(30).weakKeys().weakValues().expireAfterAccess(10L,TimeUnit.MINUTES).expireAfterWrite(1L,TimeUnit.HOURS);
  assertCacheBuilderEquivalence(expected,CacheBuilder.from(spec));
}
Program: 60166
Project: 60166
Buggy source:
private void assertCacheBuilderEquivalence(CacheBuilder a,CacheBuilder b){
  for (  Field f : CacheBuilder.class.getFields()) {
    f.setAccessible(true);
    try {
      assertEquals("String_Node_Str" + f.getName() + "String_Node_Str",f.get(a),f.get(b));
    }
 catch (    IllegalArgumentException e) {
      throw new AssertionError(e.getMessage());
    }
catch (    IllegalAccessException e) {
      throw new AssertionError(e.getMessage());
    }
  }
}

Fixed version (ground truth):
private static void assertCacheBuilderEquivalence(CacheBuilder a,CacheBuilder b){
  assertEquals("String_Node_Str",a.concurrencyLevel,b.concurrencyLevel);
  assertEquals("String_Node_Str",a.expireAfterAccessNanos,b.expireAfterAccessNanos);
  assertEquals("String_Node_Str",a.expireAfterWriteNanos,b.expireAfterWriteNanos);
  assertEquals("String_Node_Str",a.initialCapacity,b.initialCapacity);
  assertEquals("String_Node_Str",a.maximumSize,b.maximumSize);
  assertEquals("String_Node_Str",a.maximumWeight,b.maximumWeight);
  assertEquals("String_Node_Str",a.refreshNanos,b.refreshNanos);
  assertEquals("String_Node_Str",a.keyEquivalence,b.keyEquivalence);
  assertEquals("String_Node_Str",a.keyStrength,b.keyStrength);
  assertEquals("String_Node_Str",a.removalListener,b.removalListener);
  assertEquals("String_Node_Str",a.weigher,b.weigher);
  assertEquals("String_Node_Str",a.valueEquivalence,b.valueEquivalence);
  assertEquals("String_Node_Str",a.valueStrength,b.valueStrength);
  assertEquals("String_Node_Str",a.statsCounterSupplier,b.statsCounterSupplier);
  assertEquals("String_Node_Str",a.ticker,b.ticker);
}
Program: 60167
Project: 60167
Buggy source:
public void testParse_accessExpirationAndWriteExpiration(){
  CacheBuilderSpec spec=parse("String_Node_Str");
  assertEquals(TimeUnit.MINUTES,spec.writeExpirationTimeUnit);
  assertEquals(9L,spec.writeExpirationDuration);
  assertEquals(TimeUnit.SECONDS,spec.accessExpirationTimeUnit);
  assertEquals(10L,spec.accessExpirationDuration);
  assertCacheBuilderEquivalence(CacheBuilder.newBuilder().expireAfterAccess(10L,TimeUnit.SECONDS),CacheBuilder.from(spec));
}

Fixed version (ground truth):
public void testParse_accessExpirationAndWriteExpiration(){
  CacheBuilderSpec spec=parse("String_Node_Str");
  assertEquals(TimeUnit.MINUTES,spec.writeExpirationTimeUnit);
  assertEquals(9L,spec.writeExpirationDuration);
  assertEquals(TimeUnit.SECONDS,spec.accessExpirationTimeUnit);
  assertEquals(10L,spec.accessExpirationDuration);
  assertCacheBuilderEquivalence(CacheBuilder.newBuilder().expireAfterAccess(10L,TimeUnit.SECONDS).expireAfterWrite(9L,TimeUnit.MINUTES),CacheBuilder.from(spec));
}
Program: 60168
Project: 60168
Buggy source:
/** 
 * Creates a   {@link CheckedFuture} out of a normal {@link ListenableFuture}and a   {@link Function} that maps from {@link Exception} instances into theappropriate checked type. <p>The given mapping function will be applied to an {@link InterruptedException}, a   {@link CancellationException}, or an  {@link ExecutionException} with the actual cause of the exception.See  {@link Future#get()} for details on the exceptions thrown.
 * @since 9.0 (source-compatible since 1.0)
 */
public static <V,X extends Exception>CheckedFuture<V,X> makeChecked(ListenableFuture<V> future,Function<Exception,X> mapper){
  return new MappingCheckedFuture<V,X>(checkNotNull(future),mapper);
}

Fixed version (ground truth):
/** 
 * Creates a   {@link CheckedFuture} out of a normal {@link ListenableFuture}and a   {@link Function} that maps from {@link Exception} instances into theappropriate checked type. <p>The given mapping function will be applied to an {@link InterruptedException}, a   {@link CancellationException}, or an  {@link ExecutionException}. See   {@link Future#get()} for details on the exceptions thrown.
 * @since 9.0 (source-compatible since 1.0)
 */
public static <V,X extends Exception>CheckedFuture<V,X> makeChecked(ListenableFuture<V> future,Function<Exception,X> mapper){
  return new MappingCheckedFuture<V,X>(checkNotNull(future),mapper);
}
Program: 60169
Project: 60169
Buggy source:
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());
}

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(ImmutableList.of(State.STARTING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60170
Project: 60170
Buggy source:
public void testManualServiceNotifyStoppedWhileRunning() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyStarted();
  service.notifyStopped();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.doStopCalled);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.TERMINATED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testManualServiceNotifyStoppedWhileRunning() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyStarted();
  service.notifyStopped();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.doStopCalled);
  assertEquals(ImmutableList.of(State.STARTING,State.RUNNING,State.TERMINATED),listener.getStateHistory());
}
Program: 60171
Project: 60171
Buggy source:
@Override protected void doStop(){
  notifyFailed(EXCEPTION);
}

Fixed version (ground truth):
@Override protected void doStop(){
}
Program: 60172
Project: 60172
Buggy source:
public void testThrowingServiceStopAndWait_runThrowing() throws Exception {
  RunThrowingService service=new RunThrowingService();
  RecordingListener listener=RecordingListener.record(service);
  service.startAndWait();
  try {
    service.stopAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals(EXCEPTION,e.getCause().getCause());
  }
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.FAILED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testThrowingServiceStopAndWait_runThrowing() throws Exception {
  RunThrowingService service=new RunThrowingService();
  RecordingListener listener=RecordingListener.record(service);
  service.startAndWait();
  try {
    service.stopAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals(service.exception,e.getCause().getCause());
  }
  assertEquals(ImmutableList.of(State.STARTING,State.RUNNING,State.FAILED),listener.getStateHistory());
}
Program: 60173
Project: 60173
Buggy source:
public void testManualServiceFailWhileRunning() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyStarted();
  service.notifyFailed(EXCEPTION);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.FAILED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testManualServiceFailWhileRunning() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyStarted();
  service.notifyFailed(EXCEPTION);
  assertEquals(ImmutableList.of(State.STARTING,State.RUNNING,State.FAILED),listener.getStateHistory());
}
Program: 60174
Project: 60174
Buggy source:
public void testThrowingServiceStopAndWait_stopThrowing() throws Exception {
  StopThrowingService service=new StopThrowingService();
  RecordingListener listener=RecordingListener.record(service);
  service.startAndWait();
  try {
    service.stopAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals(EXCEPTION,e.getCause());
  }
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.FAILED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testThrowingServiceStopAndWait_stopThrowing() throws Exception {
  StopThrowingService service=new StopThrowingService();
  RecordingListener listener=RecordingListener.record(service);
  service.startAndWait();
  try {
    service.stopAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals(service.exception,e.getCause());
  }
  assertEquals(ImmutableList.of(State.STARTING,State.RUNNING,State.STOPPING,State.FAILED),listener.getStateHistory());
}
Program: 60175
Project: 60175
Buggy source:
public void testManualServiceStopWhileNew() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.doStartCalled);
  assertFalse(service.doStopCalled);
  assertEquals(Arrays.asList(State.TERMINATED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testManualServiceStopWhileNew() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.stop();
  assertEquals(State.TERMINATED,service.state());
  assertFalse(service.isRunning());
  assertFalse(service.doStartCalled);
  assertFalse(service.doStopCalled);
  assertEquals(ImmutableList.of(State.TERMINATED),listener.getStateHistory());
}
Program: 60176
Project: 60176
Buggy source:
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());
}

Fixed version (ground truth):
public void testAddListenerAfterFailureDoesntCauseDeadlock() throws InterruptedException {
  final StartFailingService service=new StartFailingService();
  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: 60177
Project: 60177
Buggy source:
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());
}

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(ImmutableList.of(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60178
Project: 60178
Buggy source:
public void testManualServiceFailWhileStopping() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyStarted();
  service.stop();
  service.notifyFailed(EXCEPTION);
  assertEquals(Arrays.asList(State.STARTING,State.RUNNING,State.STOPPING,State.FAILED),listener.getStateHistory());
}

Fixed version (ground truth):
public void testManualServiceFailWhileStopping() throws Exception {
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyStarted();
  service.stop();
  service.notifyFailed(EXCEPTION);
  assertEquals(ImmutableList.of(State.STARTING,State.RUNNING,State.STOPPING,State.FAILED),listener.getStateHistory());
}
Program: 60179
Project: 60179
Buggy source:
public void testManualServiceFailureIdempotence(){
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener listener=RecordingListener.record(service);
  service.start();
  service.notifyFailed(new Exception("String_Node_Str"));
  service.notifyFailed(new Exception("String_Node_Str"));
  try {
    service.startAndWait();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals("String_Node_Str",e.getCause().getMessage());
  }
}

Fixed version (ground truth):
public void testManualServiceFailureIdempotence(){
  ManualSwitchedService service=new ManualSwitchedService();
  RecordingListener.record(service);
  service.start();
  service.notifyFailed(new Exception("String_Node_Str"));
  service.notifyFailed(new Exception("String_Node_Str"));
  try {
    service.startAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    assertEquals("String_Node_Str",e.getCause().getMessage());
  }
}
Program: 60180
Project: 60180
Buggy source:
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());
}

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(ImmutableList.of(State.STARTING,State.RUNNING,State.STOPPING,State.TERMINATED),listener.getStateHistory());
}
Program: 60181
Project: 60181
Buggy source:
@Override public synchronized void failed(State from,Throwable failure){
  assertEquals(from,Iterables.getLast(stateHistory));
  stateHistory.add(State.FAILED);
  assertEquals(State.FAILED,service.state());
  if (from == State.STARTING) {
    try {
      service.startAndWait();
    }
 catch (    UncheckedExecutionException e) {
      assertEquals(failure,e.getCause());
    }
  }
  try {
    service.stopAndWait();
  }
 catch (  UncheckedExecutionException e) {
    if (from == State.STOPPING) {
      assertEquals(failure,e.getCause());
    }
 else {
      assertEquals(failure,e.getCause().getCause());
    }
  }
  completionLatch.countDown();
}

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());
  if (from == State.STARTING) {
    try {
      service.startAndWait();
      fail();
    }
 catch (    UncheckedExecutionException e) {
      assertEquals(failure,e.getCause());
    }
  }
  try {
    service.stopAndWait();
    fail();
  }
 catch (  UncheckedExecutionException e) {
    if (from == State.STOPPING) {
      assertEquals(failure,e.getCause());
    }
 else {
      assertEquals(failure,e.getCause().getCause());
    }
  }
  completionLatch.countDown();
}