Program: 42602
Project: 42602
Buggy source:
/** 
 * Run GenericHandler method with adapters, filters and injectors. If the class is   {@link Handler}, it will only run when there is at least one adapter on it.
 * @param m                  The method to run
 * @param requiredAnnotation Method will run when has requiredAnnotation. If it is null, method will run.
 * @return The method's return. Or NO_ADAPTER if do not match the request.
 * @see org.binwang.bard.core.Filter
 * @see org.binwang.bard.core.Adapter
 * @see org.binwang.bard.core.Injector
 * @see org.binwang.bard.core.Handler
 */
protected Object runMethod(Method m,Class<? extends Annotation> requiredAnnotation) throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
  Boolean findRequiredAnnotation=false;
  Boolean findAdapterOnMethod=false;
  NoAdapter noAdapter=NoAdapter.NO_ADAPTER;
  Annotation[] methodAnnotations=m.getAnnotations();
  Annotation[] classAnnotations=this.getClass().getAnnotations();
  LinkedList<Adapter> adapters=new LinkedList<>();
  Filter[] filters=new Filter[methodAnnotations.length + classAnnotations.length];
  int filterSize=0;
  for (int i=0; i < methodAnnotations.length + classAnnotations.length; i++) {
    Annotation annotation;
    if (i < methodAnnotations.length) {
      annotation=methodAnnotations[i];
    }
 else {
      annotation=classAnnotations[i - methodAnnotations.length];
    }
    Class<? extends Annotation> annotationClass=annotation.annotationType();
    if (annotationClass == requiredAnnotation) {
      findRequiredAnnotation=true;
    }
    Class<? extends Adapter> adapterClass=mapper.adapterMap.get(annotationClass);
    if (adapterClass != null) {
      Adapter adapter=newFromThis(adapterClass,Object.class,annotation);
      adapters.add(adapter);
      if (i < methodAnnotations.length) {
        findAdapterOnMethod=true;
      }
    }
    Class<? extends Filter> filterClass=mapper.filterMap.get(annotationClass);
    if (filterClass != null) {
      Filter filter=newFromThis(filterClass,Object.class,annotation);
      filters[filterSize++]=filter;
    }
  }
  if (!findRequiredAnnotation && requiredAnnotation != null) {
    return noAdapter;
  }
  if (this instanceof Handler && !findAdapterOnMethod) {
    return noAdapter;
  }
  for (  Adapter adapter : adapters) {
    if (!adapter.match()) {
      return noAdapter;
    }
  }
  Object result=null;
  int filterI=0;
  int injectorI;
  LinkedList<LinkedList<Injector>> injectors=new LinkedList<>();
  try {
    for (; filterI < filterSize; filterI++) {
      filters[filterI].context=context;
      filters[filterI].before();
      context=filters[filterI].context;
    }
    Parameter[] parameters=m.getParameters();
    Object args[]=new Object[parameters.length];
    for (injectorI=0; injectorI < parameters.length; injectorI++) {
      Annotation[] annotations=parameters[injectorI].getAnnotations();
      Class parameterClass=parameters[injectorI].getType();
      LinkedList<Injector> paramInjectors=new LinkedList<>();
      injectors.addFirst(paramInjectors);
      Object var=null;
      for (      Annotation annotation : annotations) {
        Class<? extends Annotation> annotationClass=annotation.annotationType();
        Class<? extends Injector> injectorClass=mapper.injectorMap.get(annotationClass);
        if (injectorClass == null) {
          continue;
        }
        Injector injector=newFromThis(injectorClass,parameterClass,annotation);
        injector.context=context;
        injector.variable=var;
        paramInjectors.addFirst(injector);
        injector.before();
        var=injector.variable;
        context=injector.context;
        if (context.exception != null) {
          throw context.exception;
        }
      }
      args[injectorI]=var;
    }
    result=m.invoke(this,args);
    if (this instanceof Handler) {
      context.result=result;
    }
  }
 catch (  final InvocationTargetException e) {
    context.exception=(Exception)e.getCause();
  }
catch (  IllegalAccessException|InstantiationException|NoSuchMethodException e) {
    e.printStackTrace();
  }
catch (  Exception e) {
    context.exception=e;
  }
 finally {
    for (    LinkedList<Injector> paramsInjectors : injectors) {
      for (      Injector injector : paramsInjectors) {
        injector.context=context;
        injector.after();
        context=injector.context;
      }
    }
    for (filterI=filterI - 1; filterI >= 0; filterI--) {
      filters[filterI].context=context;
      filters[filterI].after();
      context=filters[filterI].context;
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Run GenericHandler method with adapters, filters and injectors. If the class is   {@link Handler}, it will only run when there is at least one adapter on it.
 * @param m                  The method to run
 * @param requiredAnnotation Method will run when has requiredAnnotation. If it is null, method will run.
 * @return The method's return. Or NO_ADAPTER if do not match the request.
 * @see org.binwang.bard.core.Filter
 * @see org.binwang.bard.core.Adapter
 * @see org.binwang.bard.core.Injector
 * @see org.binwang.bard.core.Handler
 */
protected Object runMethod(Method m,Class<? extends Annotation> requiredAnnotation) throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
  Boolean findRequiredAnnotation=false;
  Boolean findAdapterOnMethod=false;
  NoAdapter noAdapter=NoAdapter.NO_ADAPTER;
  Annotation[] methodAnnotations=m.getAnnotations();
  Annotation[] classAnnotations=this.getClass().getAnnotations();
  LinkedList<Adapter> adapters=new LinkedList<>();
  Filter[] filters=new Filter[methodAnnotations.length + classAnnotations.length];
  int filterSize=0;
  for (int i=0; i < methodAnnotations.length + classAnnotations.length; i++) {
    Annotation annotation;
    if (i < methodAnnotations.length) {
      annotation=methodAnnotations[i];
    }
 else {
      annotation=classAnnotations[i - methodAnnotations.length];
    }
    Class<? extends Annotation> annotationClass=annotation.annotationType();
    if (annotationClass == requiredAnnotation) {
      findRequiredAnnotation=true;
    }
    Class<? extends Adapter> adapterClass=mapper.adapterMap.get(annotationClass);
    if (adapterClass != null) {
      Adapter adapter=newFromThis(adapterClass,Object.class,annotation);
      adapters.add(adapter);
      if (i < methodAnnotations.length) {
        findAdapterOnMethod=true;
      }
    }
    Class<? extends Filter> filterClass=mapper.filterMap.get(annotationClass);
    if (filterClass != null) {
      Filter filter=newFromThis(filterClass,Object.class,annotation);
      filters[filterSize++]=filter;
    }
  }
  if (!findRequiredAnnotation && requiredAnnotation != null) {
    return noAdapter;
  }
  if (this instanceof Handler && !findAdapterOnMethod) {
    return noAdapter;
  }
  for (  Adapter adapter : adapters) {
    if (!adapter.match()) {
      return noAdapter;
    }
  }
  Object result=null;
  int filterI=0;
  int injectorI;
  LinkedList<LinkedList<Injector>> injectors=new LinkedList<>();
  LinkedList<Filter> runFilters=new LinkedList<>();
  try {
    for (; filterI < filterSize; filterI++) {
      filters[filterI].context=context;
      runFilters.addFirst(filters[filterI]);
      filters[filterI].before();
      context=filters[filterI].context;
      if (context.exception != null) {
        throw context.exception;
      }
    }
    Parameter[] parameters=m.getParameters();
    Object args[]=new Object[parameters.length];
    for (injectorI=0; injectorI < parameters.length; injectorI++) {
      Annotation[] annotations=parameters[injectorI].getAnnotations();
      Class parameterClass=parameters[injectorI].getType();
      LinkedList<Injector> paramInjectors=new LinkedList<>();
      injectors.addFirst(paramInjectors);
      Object var=null;
      for (      Annotation annotation : annotations) {
        Class<? extends Annotation> annotationClass=annotation.annotationType();
        Class<? extends Injector> injectorClass=mapper.injectorMap.get(annotationClass);
        if (injectorClass == null) {
          continue;
        }
        Injector injector=newFromThis(injectorClass,parameterClass,annotation);
        injector.context=context;
        injector.variable=var;
        paramInjectors.addFirst(injector);
        injector.before();
        var=injector.variable;
        context=injector.context;
        if (context.exception != null) {
          throw context.exception;
        }
      }
      args[injectorI]=var;
    }
    result=m.invoke(this,args);
    if (this instanceof Handler) {
      context.result=result;
    }
  }
 catch (  final InvocationTargetException e) {
    context.exception=(Exception)e.getCause();
  }
catch (  IllegalAccessException|InstantiationException|NoSuchMethodException e) {
    e.printStackTrace();
  }
catch (  Exception e) {
    context.exception=e;
  }
 finally {
    for (    LinkedList<Injector> paramsInjectors : injectors) {
      for (      Injector injector : paramsInjectors) {
        injector.context=context;
        injector.after();
        context=injector.context;
      }
    }
    for (    Filter filter : runFilters) {
      filter.context=context;
      filter.after();
      context=filter.context;
    }
  }
  return result;
}