Program: 27834
Project: 27834
Buggy source:
/** 
 * Remove useless switches and cases.
 */
private Node tryOptimizeSwitch(Node n){
  Preconditions.checkState(n.isSwitch());
  Node defaultCase=tryOptimizeDefaultCase(n);
  if (defaultCase == null) {
    Node cond=n.getFirstChild(), prev=null, next=null, cur;
    for (cur=cond.getNext(); cur != null; cur=next) {
      next=cur.getNext();
      if (!mayHaveSideEffects(cur.getFirstChild()) && isUselessCase(cur,prev)) {
        removeCase(n,cur);
      }
 else {
        prev=cur;
      }
    }
    if (NodeUtil.isLiteralValue(cond,false)) {
      Node caseLabel;
      TernaryValue caseMatches=TernaryValue.TRUE;
      for (cur=cond.getNext(); cur != null; cur=next) {
        next=cur.getNext();
        caseLabel=cur.getFirstChild();
        caseMatches=PeepholeFoldConstants.evaluateComparison(Token.SHEQ,cond,caseLabel);
        if (caseMatches == TernaryValue.TRUE) {
          break;
        }
 else         if (caseMatches == TernaryValue.UNKNOWN) {
          break;
        }
 else {
          removeCase(n,cur);
        }
      }
      if (caseMatches != TernaryValue.UNKNOWN) {
        Node block, lastStm;
        while (cur != null) {
          block=cur.getLastChild();
          lastStm=block.getLastChild();
          cur=cur.getNext();
          if (lastStm != null && lastStm.isBreak()) {
            block.removeChild(lastStm);
            reportCodeChange();
            break;
          }
        }
        for (; cur != null; cur=next) {
          next=cur.getNext();
          removeCase(n,cur);
        }
        cur=cond.getNext();
        if (cur != null && cur.getNext() == null) {
          block=cur.getLastChild();
          if (!(NodeUtil.containsType(block,Token.BREAK,NodeUtil.MATCH_NOT_FUNCTION))) {
            cur.removeChild(block);
            n.getParent().replaceChild(n,block);
            reportCodeChange();
            return block;
          }
        }
      }
    }
  }
  if (n.hasOneChild()) {
    Node condition=n.removeFirstChild();
    Node replacement=IR.exprResult(condition).srcref(n);
    n.getParent().replaceChild(n,replacement);
    reportCodeChange();
    return replacement;
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Remove useless switches and cases.
 */
private Node tryOptimizeSwitch(Node n){
  Preconditions.checkState(n.isSwitch());
  Node defaultCase=tryOptimizeDefaultCase(n);
  if (defaultCase == null) {
    Node cond=n.getFirstChild(), prev=null, next=null, cur;
    for (cur=cond.getNext(); cur != null; cur=next) {
      next=cur.getNext();
      if (!mayHaveSideEffects(cur.getFirstChild()) && isUselessCase(cur,prev)) {
        removeCase(n,cur);
      }
 else {
        prev=cur;
      }
    }
    if (NodeUtil.isLiteralValue(cond,false)) {
      Node caseLabel;
      TernaryValue caseMatches=TernaryValue.TRUE;
      for (cur=cond.getNext(); cur != null; cur=next) {
        next=cur.getNext();
        caseLabel=cur.getFirstChild();
        caseMatches=PeepholeFoldConstants.evaluateComparison(Token.SHEQ,cond,caseLabel);
        if (caseMatches == TernaryValue.TRUE) {
          break;
        }
 else         if (caseMatches == TernaryValue.UNKNOWN) {
          break;
        }
 else {
          removeCase(n,cur);
        }
      }
      if (caseMatches != TernaryValue.UNKNOWN) {
        Node block, lastStm;
        while (cur != null) {
          block=cur.getLastChild();
          lastStm=block.getLastChild();
          cur=cur.getNext();
          if (lastStm != null && lastStm.isBreak() && !lastStm.hasChildren()) {
            block.removeChild(lastStm);
            reportCodeChange();
            break;
          }
        }
        for (; cur != null; cur=next) {
          next=cur.getNext();
          removeCase(n,cur);
        }
        cur=cond.getNext();
        if (cur != null && cur.getNext() == null) {
          block=cur.getLastChild();
          if (!(NodeUtil.has(block,MATCH_UNNAMED_BREAK,NodeUtil.MATCH_NOT_FUNCTION))) {
            cur.removeChild(block);
            block.setIsSyntheticBlock(false);
            n.getParent().replaceChild(n,block);
            reportCodeChange();
            return block;
          }
        }
      }
    }
  }
  if (n.hasOneChild()) {
    Node condition=n.removeFirstChild();
    Node replacement=IR.exprResult(condition).srcref(n);
    n.getParent().replaceChild(n,replacement);
    reportCodeChange();
    return replacement;
  }
  return null;
}