Program: 17277
Project: 17277
Buggy source:
/** 
 * Parse the parameters for a Method and create immutable   {@link CacheParameterDetails} lists
 * @param method The method to get parameter detail information for
 * @param cacheValueAllowed If the {@link CacheValue} annotation is legal for this method
 * @return a ParameterDetails object, the lists it contains must be immutable.
 */
protected ParameterDetails getParameterDetails(final Method method,final boolean cacheValueAllowed){
  final Class<?>[] parameterTypes=method.getParameterTypes();
  final Annotation[][] parameterAnnotations=method.getParameterAnnotations();
  final ArrayList<CacheParameterDetails> allParameters=new ArrayList<CacheParameterDetails>(parameterTypes.length);
  final ArrayList<CacheParameterDetails> keyParameters=new ArrayList<CacheParameterDetails>(parameterTypes.length);
  CacheParameterDetails cacheValueParameter=null;
  for (int pIdx=0; pIdx < parameterTypes.length; pIdx++) {
    final Class<?> rawType=parameterTypes[pIdx];
    boolean isKey=false;
    boolean isValue=false;
    final Set<Annotation> annotations=new LinkedHashSet<Annotation>();
    for (    final Annotation parameterAnnotation : parameterAnnotations[pIdx]) {
      annotations.add(parameterAnnotation);
      if (!isKey && CacheKeyParam.class.isAssignableFrom(parameterAnnotation.annotationType())) {
        isKey=true;
      }
 else       if (CacheValue.class.isAssignableFrom(parameterAnnotation.annotationType())) {
        if (!cacheValueAllowed) {
          throw new AnnotationFormatError("String_Node_Str" + method);
        }
 else         if (cacheValueParameter != null || isValue) {
          throw new AnnotationFormatError("String_Node_Str" + method);
        }
 else {
          isValue=true;
        }
      }
    }
    final CacheParameterDetails cacheParameterDetails=new CacheParameterDetails(rawType,Collections.unmodifiableSet(annotations),pIdx);
    allParameters.add(cacheParameterDetails);
    if (isKey) {
      keyParameters.add(cacheParameterDetails);
    }
    if (isValue) {
      cacheValueParameter=cacheParameterDetails;
    }
  }
  if (keyParameters.isEmpty()) {
    keyParameters.addAll(allParameters);
  }
  if (cacheValueParameter != null) {
    keyParameters.remove(cacheValueParameter);
  }
  keyParameters.trimToSize();
  return new ParameterDetails(Collections.unmodifiableList(allParameters),Collections.unmodifiableList(keyParameters),cacheValueParameter);
}

Fixed version (ground truth):
/** 
 * Parse the parameters for a Method and create immutable   {@link CacheParameterDetails} lists
 * @param method The method to get parameter detail information for
 * @param cacheValueAllowed If the {@link CacheValue} annotation is legal for this method
 * @return a ParameterDetails object, the lists it contains must be immutable.
 */
protected ParameterDetails getParameterDetails(final Method method,final boolean cacheValueAllowed){
  final Class<?>[] parameterTypes=method.getParameterTypes();
  final Annotation[][] parameterAnnotations=method.getParameterAnnotations();
  final ArrayList<CacheParameterDetails> allParameters=new ArrayList<CacheParameterDetails>(parameterTypes.length);
  final ArrayList<CacheParameterDetails> keyParameters=new ArrayList<CacheParameterDetails>(parameterTypes.length);
  CacheParameterDetails cacheValueParameter=null;
  for (int pIdx=0; pIdx < parameterTypes.length; pIdx++) {
    final Class<?> rawType=parameterTypes[pIdx];
    boolean isKey=false;
    boolean isValue=false;
    final Set<Annotation> annotations=new LinkedHashSet<Annotation>();
    for (    final Annotation parameterAnnotation : parameterAnnotations[pIdx]) {
      annotations.add(parameterAnnotation);
      if (!isKey && CacheKey.class.isAssignableFrom(parameterAnnotation.annotationType())) {
        isKey=true;
      }
 else       if (CacheValue.class.isAssignableFrom(parameterAnnotation.annotationType())) {
        if (!cacheValueAllowed) {
          throw new AnnotationFormatError("String_Node_Str" + method);
        }
 else         if (cacheValueParameter != null || isValue) {
          throw new AnnotationFormatError("String_Node_Str" + method);
        }
 else {
          isValue=true;
        }
      }
    }
    final CacheParameterDetails cacheParameterDetails=new CacheParameterDetails(rawType,Collections.unmodifiableSet(annotations),pIdx);
    allParameters.add(cacheParameterDetails);
    if (isKey) {
      keyParameters.add(cacheParameterDetails);
    }
    if (isValue) {
      cacheValueParameter=cacheParameterDetails;
    }
  }
  if (keyParameters.isEmpty()) {
    keyParameters.addAll(allParameters);
  }
  if (cacheValueParameter != null) {
    keyParameters.remove(cacheValueParameter);
  }
  keyParameters.trimToSize();
  return new ParameterDetails(Collections.unmodifiableList(allParameters),Collections.unmodifiableList(keyParameters),cacheValueParameter);
}