Program: 75094
Project: 75094
Buggy source:
/** 
 * Create a set checkpoint method for a class, which sets its checkpoint object.
 * @param ast The {@link AST} object.
 * @param root The root of the AST.
 * @param state The current state of the type analyzer.
 * @param isAnonymous Whether the current class is anonymous.
 * @return The declaration of the method that sets the checkpoint object.
 */
private MethodDeclaration _createSetCheckpointMethod(AST ast,CompilationUnit root,TypeAnalyzerState state,boolean isAnonymous){
  String methodName=_getSetCheckpointMethodName(isAnonymous);
  Class currentClass=state.getCurrentClass();
  Class parent=currentClass.getSuperclass();
  if (hasMethod(currentClass,methodName,new Class[]{Checkpoint.class},true))   throw new ASTDuplicatedMethodException(currentClass.getName(),methodName);
  if (parent != null && (state.getCrossAnalyzedTypes().contains(parent.getName())) || hasMethod(parent,methodName,new Class[]{Checkpoint.class}))   return null;
  MethodDeclaration method=ast.newMethodDeclaration();
  method.setName(ast.newSimpleName(methodName));
  SingleVariableDeclaration checkpoint=ast.newSingleVariableDeclaration();
  String checkpointType=getClassName(Checkpoint.class,state,root);
  checkpoint.setType(createType(ast,checkpointType));
  checkpoint.setName(ast.newSimpleName("String_Node_Str"));
  method.parameters().add(checkpoint);
  method.setReturnType(createType(ast,getClassName(Object.class,state,root)));
  IfStatement test=ast.newIfStatement();
  InfixExpression testExpression=ast.newInfixExpression();
  testExpression.setLeftOperand(ast.newSimpleName(CHECKPOINT_NAME));
  testExpression.setOperator(InfixExpression.Operator.NOT_EQUALS);
  testExpression.setRightOperand(ast.newSimpleName("String_Node_Str"));
  test.setExpression(testExpression);
  Block thenBranch=ast.newBlock();
  test.setThenStatement(thenBranch);
  Block body=ast.newBlock();
  body.statements().add(test);
  method.setBody(body);
  VariableDeclarationFragment fragment=ast.newVariableDeclarationFragment();
  fragment.setName(ast.newSimpleName("String_Node_Str"));
  fragment.setInitializer(ast.newSimpleName(CHECKPOINT_NAME));
  VariableDeclarationStatement tempDeclaration=ast.newVariableDeclarationStatement(fragment);
  tempDeclaration.setType(createType(ast,checkpointType));
  thenBranch.statements().add(tempDeclaration);
  IfStatement testNewCheckpoint=ast.newIfStatement();
  InfixExpression testNull=ast.newInfixExpression();
  testNull.setLeftOperand(ast.newSimpleName("String_Node_Str"));
  testNull.setOperator(InfixExpression.Operator.NOT_EQUALS);
  testNull.setRightOperand(ast.newNullLiteral());
  testNewCheckpoint.setExpression(testNull);
  Block testNewCheckpointBody=ast.newBlock();
  testNewCheckpoint.setThenStatement(testNewCheckpointBody);
  MethodInvocation record=ast.newMethodInvocation();
  record.setExpression(ast.newSimpleName(CHECKPOINT_RECORD_NAME));
  record.setName(ast.newSimpleName("String_Node_Str"));
  record.arguments().add(ast.newSimpleName(CHECKPOINT_NAME));
  MethodInvocation getTimestamp=ast.newMethodInvocation();
  getTimestamp.setExpression(ast.newSimpleName("String_Node_Str"));
  getTimestamp.setName(ast.newSimpleName("String_Node_Str"));
  record.arguments().add(getTimestamp);
  testNewCheckpointBody.statements().add(ast.newExpressionStatement(record));
  MethodInvocation pushStates=ast.newMethodInvocation();
  String recordType=getClassName(FieldRecord.class,state,root);
  pushStates.setExpression(createName(ast,recordType));
  pushStates.setName(ast.newSimpleName("String_Node_Str"));
  pushStates.arguments().add(ast.newSimpleName(RECORDS_NAME));
  testNewCheckpointBody.statements().add(ast.newExpressionStatement(pushStates));
  thenBranch.statements().add(testNewCheckpoint);
  Assignment assignment=ast.newAssignment();
  assignment.setLeftHandSide(ast.newSimpleName(CHECKPOINT_NAME));
  assignment.setRightHandSide(ast.newSimpleName("String_Node_Str"));
  ExpressionStatement statement=ast.newExpressionStatement(assignment);
  thenBranch.statements().add(statement);
  MethodInvocation propagate=ast.newMethodInvocation();
  propagate.setExpression(ast.newSimpleName("String_Node_Str"));
  propagate.setName(ast.newSimpleName("String_Node_Str"));
  propagate.arguments().add(ast.newSimpleName("String_Node_Str"));
  thenBranch.statements().add(ast.newExpressionStatement(propagate));
  MethodInvocation addInvocation=ast.newMethodInvocation();
  addInvocation.setExpression(ast.newSimpleName("String_Node_Str"));
  addInvocation.setName(ast.newSimpleName("String_Node_Str"));
  addInvocation.arguments().add(_createRollbackableObject(ast,isAnonymous));
  thenBranch.statements().add(ast.newExpressionStatement(addInvocation));
  ReturnStatement returnStatement=ast.newReturnStatement();
  returnStatement.setExpression(ast.newThisExpression());
  body.statements().add(returnStatement);
  method.setModifiers(Modifier.PUBLIC | Modifier.FINAL);
  addToLists(_checkParentMethods,parent.getName(),method);
  return method;
}

Fixed version (ground truth):
/** 
 * Create a set checkpoint method for a class, which sets its checkpoint object.
 * @param ast The {@link AST} object.
 * @param root The root of the AST.
 * @param state The current state of the type analyzer.
 * @param isAnonymous Whether the current class is anonymous.
 * @return The declaration of the method that sets the checkpoint object.
 */
private MethodDeclaration _createSetCheckpointMethod(AST ast,CompilationUnit root,TypeAnalyzerState state,boolean isAnonymous){
  String methodName=_getSetCheckpointMethodName(isAnonymous);
  Class currentClass=state.getCurrentClass();
  Class parent=currentClass.getSuperclass();
  if (hasMethod(currentClass,methodName,new Class[]{Checkpoint.class},true))   throw new ASTDuplicatedMethodException(currentClass.getName(),methodName);
  if (!isAnonymous && parent != null && (state.getCrossAnalyzedTypes().contains(parent.getName()) || hasMethod(parent,methodName,new Class[]{Checkpoint.class})))   return null;
  MethodDeclaration method=ast.newMethodDeclaration();
  method.setName(ast.newSimpleName(methodName));
  SingleVariableDeclaration checkpoint=ast.newSingleVariableDeclaration();
  String checkpointType=getClassName(Checkpoint.class,state,root);
  checkpoint.setType(createType(ast,checkpointType));
  checkpoint.setName(ast.newSimpleName("String_Node_Str"));
  method.parameters().add(checkpoint);
  method.setReturnType(createType(ast,getClassName(Object.class,state,root)));
  IfStatement test=ast.newIfStatement();
  InfixExpression testExpression=ast.newInfixExpression();
  testExpression.setLeftOperand(ast.newSimpleName(CHECKPOINT_NAME));
  testExpression.setOperator(InfixExpression.Operator.NOT_EQUALS);
  testExpression.setRightOperand(ast.newSimpleName("String_Node_Str"));
  test.setExpression(testExpression);
  Block thenBranch=ast.newBlock();
  test.setThenStatement(thenBranch);
  Block body=ast.newBlock();
  body.statements().add(test);
  method.setBody(body);
  VariableDeclarationFragment fragment=ast.newVariableDeclarationFragment();
  fragment.setName(ast.newSimpleName("String_Node_Str"));
  fragment.setInitializer(ast.newSimpleName(CHECKPOINT_NAME));
  VariableDeclarationStatement tempDeclaration=ast.newVariableDeclarationStatement(fragment);
  tempDeclaration.setType(createType(ast,checkpointType));
  thenBranch.statements().add(tempDeclaration);
  IfStatement testNewCheckpoint=ast.newIfStatement();
  InfixExpression testNull=ast.newInfixExpression();
  testNull.setLeftOperand(ast.newSimpleName("String_Node_Str"));
  testNull.setOperator(InfixExpression.Operator.NOT_EQUALS);
  testNull.setRightOperand(ast.newNullLiteral());
  testNewCheckpoint.setExpression(testNull);
  Block testNewCheckpointBody=ast.newBlock();
  testNewCheckpoint.setThenStatement(testNewCheckpointBody);
  MethodInvocation record=ast.newMethodInvocation();
  record.setExpression(ast.newSimpleName(CHECKPOINT_RECORD_NAME));
  record.setName(ast.newSimpleName("String_Node_Str"));
  record.arguments().add(ast.newSimpleName(CHECKPOINT_NAME));
  MethodInvocation getTimestamp=ast.newMethodInvocation();
  getTimestamp.setExpression(ast.newSimpleName("String_Node_Str"));
  getTimestamp.setName(ast.newSimpleName("String_Node_Str"));
  record.arguments().add(getTimestamp);
  testNewCheckpointBody.statements().add(ast.newExpressionStatement(record));
  MethodInvocation pushStates=ast.newMethodInvocation();
  String recordType=getClassName(FieldRecord.class,state,root);
  pushStates.setExpression(createName(ast,recordType));
  pushStates.setName(ast.newSimpleName("String_Node_Str"));
  pushStates.arguments().add(ast.newSimpleName(RECORDS_NAME));
  testNewCheckpointBody.statements().add(ast.newExpressionStatement(pushStates));
  thenBranch.statements().add(testNewCheckpoint);
  Assignment assignment=ast.newAssignment();
  assignment.setLeftHandSide(ast.newSimpleName(CHECKPOINT_NAME));
  assignment.setRightHandSide(ast.newSimpleName("String_Node_Str"));
  ExpressionStatement statement=ast.newExpressionStatement(assignment);
  thenBranch.statements().add(statement);
  MethodInvocation propagate=ast.newMethodInvocation();
  propagate.setExpression(ast.newSimpleName("String_Node_Str"));
  propagate.setName(ast.newSimpleName("String_Node_Str"));
  propagate.arguments().add(ast.newSimpleName("String_Node_Str"));
  thenBranch.statements().add(ast.newExpressionStatement(propagate));
  MethodInvocation addInvocation=ast.newMethodInvocation();
  addInvocation.setExpression(ast.newSimpleName("String_Node_Str"));
  addInvocation.setName(ast.newSimpleName("String_Node_Str"));
  addInvocation.arguments().add(_createRollbackableObject(ast,isAnonymous));
  thenBranch.statements().add(ast.newExpressionStatement(addInvocation));
  ReturnStatement returnStatement=ast.newReturnStatement();
  returnStatement.setExpression(ast.newThisExpression());
  body.statements().add(returnStatement);
  method.setModifiers(Modifier.PUBLIC | Modifier.FINAL);
  if (!isAnonymous)   addToLists(_checkParentMethods,parent.getName(),method);
  return method;
}