Program: 93683
Project: 93683
Buggy source:
/** 
 * Filter only those resolved corresponding elements whose state is valid. In case there are too many elements resolved, i.e. the number of resolved elements is greater than <code>maxElements</code>, then only the first <code>#maxElements</code> are used!!! <b>This is just a heuristic and might remove wanted and return unwanted elements!!! So the user should ALWAYS check the resolution manually!!!</b>
 * @param change The change under investigation.
 * @param mapping The resolution of all changes.
 * @param maxElements The maximum number of resolved corresponding elements allowed.
 * @param reduce If <code>true</code>, then the resolutions might be reduced to the maximum number of allowed elements as defined by <code>maxElements</code>. However, it might remove good matches, too!
 * @param forward The direction of resolution.
 * @return <code>true</code> if the resolution could be fixed for the given conditions, <code>false</code>otherwise.
 */
private static boolean filterValidStates(IndepChange change,ResolvedSymbolicReferences mapping,int maxElements,boolean reduce,boolean forward){
  final Map<IElementReference,List<EObject>> changeMapping=mapping.getResolutionByChange().get(change);
  final List<EObject> resolvedElements=changeMapping.get(change.getCorrespondingElement());
  final List<EObject> allResolvedElements=new ArrayList<EObject>(resolvedElements);
  final List<EObject> validElements=new ArrayList<EObject>(resolvedElements.size());
  for (  EObject element : allResolvedElements) {
    resolvedElements.clear();
    resolvedElements.add(element);
    final ValidationResult state=MPatchValidator.validateElementState(change,mapping,true,forward);
    if (ValidationResult.STATE_BEFORE.equals(state) || ValidationResult.STATE_AFTER.equals(state))     validElements.add(element);
  }
  resolvedElements.clear();
  final int count=reduce ? Math.min(maxElements,validElements.size()) : validElements.size();
  for (int i=0; i < count; i++) {
    resolvedElements.add(validElements.get(i));
  }
  return !resolvedElements.isEmpty();
}

Fixed version (ground truth):
/** 
 * Filter only those resolved corresponding elements whose state is valid. In case there are too many elements resolved, i.e. the number of resolved elements is greater than <code>maxElements</code>, then only the first <code>#maxElements</code> are used!!! <b>This is just a heuristic and might remove wanted and return unwanted elements!!! So the user should ALWAYS check the resolution manually!!!</b>
 * @param change The change under investigation.
 * @param mapping The resolution of all changes.
 * @param maxElements The maximum number of resolved corresponding elements allowed.
 * @param reduce If <code>true</code>, then the resolutions might be reduced to the maximum number of allowed elements as defined by <code>maxElements</code>. However, it might remove good matches, too!
 * @param forward The direction of resolution.
 * @return <code>true</code> if the resolution could be fixed for the given conditions, <code>false</code>otherwise.
 */
private static boolean filterValidStates(IndepChange change,ResolvedSymbolicReferences mapping,int maxElements,boolean reduce,boolean forward){
  final Map<IElementReference,List<EObject>> changeMapping=mapping.getResolutionByChange().get(change);
  final List<EObject> resolvedElements=changeMapping.get(change.getCorrespondingElement());
  final List<EObject> allResolvedElements=new ArrayList<EObject>(resolvedElements);
  final List<EObject> beforeElements=new ArrayList<EObject>(resolvedElements.size());
  final List<EObject> afterElements=new ArrayList<EObject>(resolvedElements.size());
  for (  EObject element : allResolvedElements) {
    resolvedElements.clear();
    resolvedElements.add(element);
    final ValidationResult state=MPatchValidator.validateElementState(change,mapping,true,forward);
    if (ValidationResult.STATE_BEFORE.equals(state))     beforeElements.add(element);
 else     if (ValidationResult.STATE_AFTER.equals(state))     afterElements.add(element);
  }
  resolvedElements.clear();
  final List<EObject> validElements=beforeElements.isEmpty() ? afterElements : beforeElements;
  final int count=reduce ? Math.min(maxElements,validElements.size()) : validElements.size();
  for (int i=0; i < count; i++) {
    resolvedElements.add(validElements.get(i));
  }
  return !resolvedElements.isEmpty();
}