public synchronized void validate() throws RuntimeException {
  if (head == null) {
    if (tail != null)     bug("Head is null but tail is set");
 else     if (array.size() != 0)     bug("Array is size > 0 when head and tail are empty");
  }
 else {
    if (tail == null)     bug("Head is set but not tail");
 else     if (head.before != null)     bug("Head position points to previous position: " + head.after);
 else     if (tail.after != null)     bug("Tail position points to following position: " + tail.after);
 else {
      ThreadPosition tp=head;
      int linkedSize;
      for (linkedSize=1; linkedSize < array.size(); linkedSize++) {
        if (tp.after == null)         break;
 else         tp=tp.after;
      }
      if (linkedSize != array.size())       bug("Linked size is different from array size: linked=" + linkedSize + " array="+ array.size());
      if (tp != tail)       bug("Last item in list is not the tail: last=[" + tp + "] tail=["+ tail+ "]");
    }
  }
}

public synchronized void validate ( ) throws RuntimeException { if ( head == null ) { if ( tail != null ) bug ( "Head is null but tail is set" ) ; else if ( array . size ( ) != 0 ) bug ( "Array is size > 0 when head and tail are empty" ) ; } else { if ( tail == null ) bug ( "Head is set but not tail" ) ; else if ( head . before != null ) bug ( "Head position points to previous position: " + head . after ) ; else if ( tail . after != null ) bug ( "Tail position points to following position: " + tail . after ) ; else { ThreadPosition tp = head ; int linkedSize ; for ( linkedSize = 1 ; linkedSize < array . size ( ) ; linkedSize ++ ) { if ( tp . after == null ) break ; else tp = tp . after ; } if ( linkedSize != array . size ( ) ) bug ( "Linked size is different from array size: linked=" + linkedSize + " array=" + array . size ( ) ) ; if ( tp != tail ) bug ( "Last item in list is not the tail: last=[" + tp + "] tail=[" + tail + "]" ) ; } } }
ensures that the array is consistent by checking various safety conditions . ( where ' s eiffel when you need it ? )
