Program: 12027
Project: 12027
Buggy source:
protected Set<ITypeBinding> getThrownExceptionTypes(Statement statement){
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  List<Expression> methodInvocations=new ArrayList<Expression>();
  List<Expression> classInstanceCreations=new ArrayList<Expression>();
  if (statement instanceof IfStatement) {
    IfStatement ifStatement=(IfStatement)statement;
    Expression ifExpression=ifStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(ifExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(ifExpression));
  }
 else   if (statement instanceof WhileStatement) {
    WhileStatement whileStatement=(WhileStatement)statement;
    Expression whileExpression=whileStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(whileExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(whileExpression));
  }
 else   if (statement instanceof ForStatement) {
    ForStatement forStatement=(ForStatement)statement;
    List<Expression> initializers=forStatement.initializers();
    for (    Expression expression : initializers) {
      methodInvocations.addAll(expressionExtractor.getMethodInvocations(expression));
      classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(expression));
    }
    Expression forExpression=forStatement.getExpression();
    if (forExpression != null) {
      methodInvocations.addAll(expressionExtractor.getMethodInvocations(forExpression));
      classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(forExpression));
    }
    List<Expression> updaters=forStatement.updaters();
    for (    Expression expression : updaters) {
      methodInvocations.addAll(expressionExtractor.getMethodInvocations(expression));
      classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(expression));
    }
  }
 else   if (statement instanceof EnhancedForStatement) {
    EnhancedForStatement enhancedForStatement=(EnhancedForStatement)statement;
    Expression expression=enhancedForStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(expression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(expression));
  }
 else   if (statement instanceof DoStatement) {
    DoStatement doStatement=(DoStatement)statement;
    Expression doExpression=doStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(doExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(doExpression));
  }
 else   if (statement instanceof SwitchStatement) {
    SwitchStatement switchStatement=(SwitchStatement)statement;
    Expression switchExpression=switchStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(switchExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(switchExpression));
  }
 else   if (statement instanceof TryStatement) {
  }
 else {
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(statement));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(statement));
  }
  Set<ITypeBinding> thrownExceptionTypes=new LinkedHashSet<ITypeBinding>();
  for (  Expression expression : methodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      IMethodBinding methodInvocationBinding=methodInvocation.resolveMethodBinding();
      ITypeBinding[] exceptionTypes=methodInvocationBinding.getExceptionTypes();
      for (      ITypeBinding typeBinding : exceptionTypes)       thrownExceptionTypes.add(typeBinding);
    }
 else     if (expression instanceof SuperMethodInvocation) {
      SuperMethodInvocation superMethodInvocation=(SuperMethodInvocation)expression;
      IMethodBinding methodInvocationBinding=superMethodInvocation.resolveMethodBinding();
      ITypeBinding[] exceptionTypes=methodInvocationBinding.getExceptionTypes();
      for (      ITypeBinding typeBinding : exceptionTypes)       thrownExceptionTypes.add(typeBinding);
    }
  }
  for (  Expression expression : classInstanceCreations) {
    ClassInstanceCreation classInstanceCreation=(ClassInstanceCreation)expression;
    IMethodBinding constructorBinding=classInstanceCreation.resolveConstructorBinding();
    ITypeBinding[] exceptionTypes=constructorBinding.getExceptionTypes();
    for (    ITypeBinding typeBinding : exceptionTypes)     thrownExceptionTypes.add(typeBinding);
  }
  if (statement instanceof ThrowStatement) {
    ThrowStatement throwStatement=(ThrowStatement)statement;
    TypeVisitor typeVisitor=new TypeVisitor();
    throwStatement.accept(typeVisitor);
    thrownExceptionTypes.addAll(typeVisitor.getTypeBindings());
  }
  return thrownExceptionTypes;
}

Fixed version (ground truth):
protected Set<ITypeBinding> getThrownExceptionTypes(Statement statement){
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  List<Expression> methodInvocations=new ArrayList<Expression>();
  List<Expression> classInstanceCreations=new ArrayList<Expression>();
  if (statement instanceof IfStatement) {
    IfStatement ifStatement=(IfStatement)statement;
    Expression ifExpression=ifStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(ifExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(ifExpression));
  }
 else   if (statement instanceof WhileStatement) {
    WhileStatement whileStatement=(WhileStatement)statement;
    Expression whileExpression=whileStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(whileExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(whileExpression));
  }
 else   if (statement instanceof ForStatement) {
    ForStatement forStatement=(ForStatement)statement;
    List<Expression> initializers=forStatement.initializers();
    for (    Expression expression : initializers) {
      methodInvocations.addAll(expressionExtractor.getMethodInvocations(expression));
      classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(expression));
    }
    Expression forExpression=forStatement.getExpression();
    if (forExpression != null) {
      methodInvocations.addAll(expressionExtractor.getMethodInvocations(forExpression));
      classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(forExpression));
    }
    List<Expression> updaters=forStatement.updaters();
    for (    Expression expression : updaters) {
      methodInvocations.addAll(expressionExtractor.getMethodInvocations(expression));
      classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(expression));
    }
  }
 else   if (statement instanceof EnhancedForStatement) {
    EnhancedForStatement enhancedForStatement=(EnhancedForStatement)statement;
    Expression expression=enhancedForStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(expression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(expression));
  }
 else   if (statement instanceof DoStatement) {
    DoStatement doStatement=(DoStatement)statement;
    Expression doExpression=doStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(doExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(doExpression));
  }
 else   if (statement instanceof SwitchStatement) {
    SwitchStatement switchStatement=(SwitchStatement)statement;
    Expression switchExpression=switchStatement.getExpression();
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(switchExpression));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(switchExpression));
  }
 else   if (statement instanceof TryStatement) {
  }
 else {
    methodInvocations.addAll(expressionExtractor.getMethodInvocations(statement));
    classInstanceCreations.addAll(expressionExtractor.getClassInstanceCreations(statement));
  }
  Set<ITypeBinding> thrownExceptionTypes=new LinkedHashSet<ITypeBinding>();
  for (  Expression expression : methodInvocations) {
    TryStatement surroundingTryBlock=surroundingTryBlock(expression);
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      IMethodBinding methodInvocationBinding=methodInvocation.resolveMethodBinding();
      ITypeBinding[] exceptionTypes=methodInvocationBinding.getExceptionTypes();
      for (      ITypeBinding typeBinding : exceptionTypes) {
        if (surroundingTryBlock == null || (surroundingTryBlock != null && !isNestedUnderAnonymousClassDeclaration(surroundingTryBlock))) {
          thrownExceptionTypes.add(typeBinding);
        }
      }
    }
 else     if (expression instanceof SuperMethodInvocation) {
      SuperMethodInvocation superMethodInvocation=(SuperMethodInvocation)expression;
      IMethodBinding methodInvocationBinding=superMethodInvocation.resolveMethodBinding();
      ITypeBinding[] exceptionTypes=methodInvocationBinding.getExceptionTypes();
      for (      ITypeBinding typeBinding : exceptionTypes) {
        if (surroundingTryBlock == null || (surroundingTryBlock != null && !isNestedUnderAnonymousClassDeclaration(surroundingTryBlock))) {
          thrownExceptionTypes.add(typeBinding);
        }
      }
    }
  }
  for (  Expression expression : classInstanceCreations) {
    TryStatement surroundingTryBlock=surroundingTryBlock(expression);
    ClassInstanceCreation classInstanceCreation=(ClassInstanceCreation)expression;
    IMethodBinding constructorBinding=classInstanceCreation.resolveConstructorBinding();
    ITypeBinding[] exceptionTypes=constructorBinding.getExceptionTypes();
    for (    ITypeBinding typeBinding : exceptionTypes) {
      if (surroundingTryBlock == null || (surroundingTryBlock != null && !isNestedUnderAnonymousClassDeclaration(surroundingTryBlock))) {
        thrownExceptionTypes.add(typeBinding);
      }
    }
  }
  if (statement instanceof ThrowStatement) {
    TryStatement surroundingTryBlock=surroundingTryBlock(statement);
    ThrowStatement throwStatement=(ThrowStatement)statement;
    TypeVisitor typeVisitor=new TypeVisitor();
    throwStatement.accept(typeVisitor);
    if (surroundingTryBlock == null || (surroundingTryBlock != null && !isNestedUnderAnonymousClassDeclaration(surroundingTryBlock))) {
      thrownExceptionTypes.addAll(typeVisitor.getTypeBindings());
    }
  }
  return thrownExceptionTypes;
}