Program: 111897
Project: 111897
Buggy source:
/** 
 * Optimizes the list of statements. If an expression is used only once, it is inlined. 
 */
private void optimize(){
  List<Slot> slots=new ArrayList<Slot>();
  final UseCounter useCounter=new UseCounter();
  for (  Statement statement : statements) {
    if (statement instanceof DeclarationExpression) {
      final Slot slot=new Slot((DeclarationExpression)statement);
      useCounter.map.put(slot.parameter,slot);
      slots.add(slot);
    }
  }
  for (  Statement statement : statements) {
    statement.accept(useCounter);
  }
  final Map<ParameterExpression,Expression> subMap=new HashMap<ParameterExpression,Expression>();
  final SubstituteVariableVisitor visitor=new SubstituteVariableVisitor(subMap);
  final ArrayList<Statement> oldStatements=new ArrayList<Statement>(statements);
  statements.clear();
  for (  Statement oldStatement : oldStatements) {
    if (oldStatement instanceof DeclarationExpression) {
      DeclarationExpression statement=(DeclarationExpression)oldStatement;
      final Slot slot=useCounter.map.get(statement.parameter);
      int count=slot.count;
      if (slot.expression instanceof ConstantExpression && ((ConstantExpression)slot.expression).value == null) {
        count=100;
      }
      if (slot.expression instanceof NewExpression && ((NewExpression)slot.expression).memberDeclarations != null) {
        count=100;
      }
switch (count) {
case 0:
        break;
case 1:
      subMap.put(slot.parameter,slot.expression);
    break;
default :
  statements.add(statement);
break;
}
}
 else {
statements.add(oldStatement.accept(visitor));
}
}
if (!subMap.isEmpty()) {
oldStatements.clear();
oldStatements.addAll(statements);
statements.clear();
for (Statement oldStatement : oldStatements) {
statements.add(oldStatement.accept(visitor));
}
}
}

Fixed version (ground truth):
/** 
 * Optimizes the list of statements. If an expression is used only once, it is inlined. 
 */
private void optimize(){
  List<Slot> slots=new ArrayList<Slot>();
  final UseCounter useCounter=new UseCounter();
  for (  Statement statement : statements) {
    if (statement instanceof DeclarationExpression) {
      final Slot slot=new Slot((DeclarationExpression)statement);
      useCounter.map.put(slot.parameter,slot);
      slots.add(slot);
    }
  }
  for (  Statement statement : statements) {
    statement.accept(useCounter);
  }
  final Map<ParameterExpression,Expression> subMap=new HashMap<ParameterExpression,Expression>();
  final SubstituteVariableVisitor visitor=new SubstituteVariableVisitor(subMap);
  final ArrayList<Statement> oldStatements=new ArrayList<Statement>(statements);
  statements.clear();
  for (  Statement oldStatement : oldStatements) {
    if (oldStatement instanceof DeclarationExpression) {
      DeclarationExpression statement=(DeclarationExpression)oldStatement;
      final Slot slot=useCounter.map.get(statement.parameter);
      int count=slot.count;
      if (Expressions.isConstantNull(slot.expression)) {
        count=100;
      }
      if (slot.expression instanceof NewExpression && ((NewExpression)slot.expression).memberDeclarations != null) {
        count=100;
      }
switch (count) {
case 0:
        break;
case 1:
      subMap.put(slot.parameter,slot.expression);
    break;
default :
  statements.add(statement);
break;
}
}
 else {
statements.add(oldStatement.accept(visitor));
}
}
if (!subMap.isEmpty()) {
oldStatements.clear();
oldStatements.addAll(statements);
statements.clear();
for (Statement oldStatement : oldStatements) {
statements.add(oldStatement.accept(visitor));
}
}
}