Program: 48087
Project: 48087
Buggy source:
/** 
 * Wait for events in the system. The SmartcardIO wait function only reacts on card events, new and removed terminals go unseen. in order to fix this, we wait only a short time and check the terminal list periodically.
 * @param timeout Timeout values as in {@link #waitForChange(long)}.
 * @return {@code true} if a change the terminals happened, {@code false} if a timeout occurred.
 */
private boolean internalWait(long timeout) throws CardException {
  if (timeout < 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
 else   if (timeout == 0) {
    timeout=Long.MAX_VALUE;
  }
  while (true) {
    if (timeout == 0) {
      return false;
    }
    long waitTime;
    if (timeout < WAIT_DELTA) {
      waitTime=timeout;
      timeout=0;
    }
 else {
      timeout=timeout - WAIT_DELTA;
      waitTime=WAIT_DELTA;
    }
    boolean change=own.terminals.waitForChange(waitTime);
    if (change) {
      return true;
    }
    ArrayList<CardTerminal> currentTerms=new ArrayList<>(own.terminals.list());
    if (currentTerms.size() != terminals.size()) {
      return true;
    }
    HashSet<String> newTermNames=new HashSet<>();
    for (    CardTerminal next : currentTerms) {
      newTermNames.add(next.getName());
    }
    int sizeBefore=newTermNames.size();
    if (sizeBefore != terminals.size()) {
      return false;
    }
    newTermNames.addAll(terminals);
    int sizeAfter=newTermNames.size();
    if (sizeBefore != sizeAfter) {
      return false;
    }
  }
}

Fixed version (ground truth):
/** 
 * Wait for events in the system. The SmartcardIO wait function only reacts on card events, new and removed terminals go unseen. in order to fix this, we wait only a short time and check the terminal list periodically.
 * @param timeout Timeout values as in {@link #waitForChange(long)}.
 * @return {@code true} if a change the terminals happened, {@code false} if a timeout occurred.
 */
private boolean internalWait(long timeout) throws CardException {
  if (timeout < 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
 else   if (timeout == 0) {
    timeout=Long.MAX_VALUE;
  }
  while (true) {
    if (timeout == 0) {
      return false;
    }
    long waitTime;
    if (timeout < WAIT_DELTA) {
      waitTime=timeout;
      timeout=0;
    }
 else {
      timeout=timeout - WAIT_DELTA;
      waitTime=WAIT_DELTA;
    }
    boolean change=own.terminals.waitForChange(1);
    if (change) {
      return true;
    }
    try {
      Thread.sleep(waitTime);
    }
 catch (    InterruptedException ex) {
      throw new CardException("String_Node_Str");
    }
    change=own.terminals.waitForChange(1);
    if (change) {
      return true;
    }
    ArrayList<CardTerminal> currentTerms=new ArrayList<>(own.terminals.list());
    if (currentTerms.size() != terminals.size()) {
      return true;
    }
    HashSet<String> newTermNames=new HashSet<>();
    for (    CardTerminal next : currentTerms) {
      newTermNames.add(next.getName());
    }
    int sizeBefore=newTermNames.size();
    if (sizeBefore != terminals.size()) {
      return false;
    }
    newTermNames.addAll(terminals);
    int sizeAfter=newTermNames.size();
    if (sizeBefore != sizeAfter) {
      return false;
    }
  }
}