Program: 185368
Project: 185368
Buggy source:
/** 
 * @param declaringType type that declares {@code declaration} in most cases;if  {@code call} is a category method it's likely the calling objecttype; if  {@code call} is an implicit-this call in a closure, then...
 */
public CallAndType(MethodCallExpression call,ASTNode declaration,ClassNode declaringType,ModuleNode enclosingModule){
  this.call=call;
  this.declaration=declaration;
  this.declaringType=declaringType;
  if (declaration instanceof MethodNode) {
    MethodNode methodNode=(MethodNode)declaration;
    Parameter[] parameters=methodNode.getParameters();
    if (parameters != null && parameters.length > 0) {
      List<Expression> arguments=null;
      if (call.getArguments() instanceof TupleExpression) {
        arguments=((TupleExpression)call.getArguments()).getExpressions();
      }
      if (arguments != null && !arguments.isEmpty()) {
        if (!methodNode.getDeclaringClass().equals(getPerceivedDeclaringType())) {
          List<Expression> categoryMethodArguments=new ArrayList<>(arguments.size() + 1);
          categoryMethodArguments.add(new ClassExpression(declaringType));
          categoryMethodArguments.addAll(arguments);
          arguments=categoryMethodArguments;
        }
        for (int i=0, n=parameters.length; i < n; i+=1) {
          List<AnnotationNode> annotations=parameters[i].getAnnotations();
          if (annotations != null && !annotations.isEmpty()) {
            for (            AnnotationNode annotation : annotations) {
              if (annotation.getClassNode().getName().equals(DELEGATES_TO.getName()) && i < arguments.size() && arguments.get(i) instanceof ClosureExpression) {
                ClosureExpression closure=(ClosureExpression)arguments.get(i);
                Expression delegatesToType=annotation.getMember("String_Node_Str");
                Expression delegatesToValue=annotation.getMember("String_Node_Str");
                Expression delegatesToTarget=annotation.getMember("String_Node_Str");
                Expression delegatesToStrategy=annotation.getMember("String_Node_Str");
                Expression delegatesToGenericTypeIndex=annotation.getMember("String_Node_Str");
                Integer strategy=null, generics=null;
                if (delegatesToStrategy != null) {
                  strategy=(Integer)evaluateExpression(castX(INTEGER_CLASS_NODE,delegatesToStrategy),enclosingModule.getUnit().getConfig());
                }
                if (delegatesToGenericTypeIndex != null) {
                  generics=(Integer)evaluateExpression(castX(INTEGER_CLASS_NODE,delegatesToGenericTypeIndex),enclosingModule.getUnit().getConfig());
                }
                if (delegatesToValue instanceof ClassExpression && !delegatesToValue.getType().getName().equals("String_Node_Str")) {
                  addDelegatesToClosure(closure,delegatesToValue.getType(),strategy);
                }
 else                 if (delegatesToType instanceof ConstantExpression && !"String_Node_Str".equals(delegatesToType.getText())) {
                  CompilationUnit compilationUnit=null;
                  ClassNode[] resolved=parseClassNodesFromString(delegatesToType.getText(),enclosingModule.getContext(),compilationUnit,methodNode,delegatesToType);
                  addDelegatesToClosure(closure,resolved[0],strategy);
                }
 else                 if (delegatesToValue == null || (delegatesToValue instanceof ClassExpression && delegatesToValue.getType().getName().equals("String_Node_Str"))) {
                  int j=indexOfDelegatesToTarget(parameters,delegatesToTarget.getText());
                  if (j >= 0 && j < arguments.size()) {
                    Expression target=arguments.get(j);
                    ClassNode targetType=target.getType();
                    if (generics != null && generics >= 0 && targetType.isUsingGenerics()) {
                      targetType.getGenericsTypes()[generics].getType();
                    }
                    addDelegatesToClosure(closure,targetType,strategy);
                  }
                }
              }
            }
          }
        }
        if (delegatesTo == null) {
          if (arguments.get(0) instanceof ClosureExpression && methodNode.getName().matches("String_Node_Str") && methodNode.getDeclaringClass().getName().equals("String_Node_Str")) {
            addDelegatesToClosure((ClosureExpression)arguments.get(0),methodNode.getDeclaringClass(),Closure.OWNER_FIRST);
          }
 else           if (arguments.size() > 1 && arguments.get(1) instanceof ClosureExpression && methodNode.getName().matches("String_Node_Str") && DGM_CLASS_NODE.equals(methodNode.getDeclaringClass())) {
            addDelegatesToClosure((ClosureExpression)arguments.get(1),declaringType,Closure.DELEGATE_FIRST);
          }
        }
      }
    }
  }
  if (delegatesTo == null) {
    delegatesTo=Collections.emptyMap();
  }
}

Fixed version (ground truth):
/** 
 * @param declaringType type that declares {@code declaration} in most cases;if  {@code call} is a category method it's likely the calling objecttype; if  {@code call} is an implicit-this call in a closure, then...
 */
public CallAndType(MethodCallExpression call,ASTNode declaration,ClassNode declaringType,ModuleNode enclosingModule){
  this.call=call;
  this.declaration=declaration;
  this.declaringType=declaringType;
  if (declaration instanceof MethodNode) {
    MethodNode methodNode=(MethodNode)declaration;
    Parameter[] parameters=methodNode.getParameters();
    if (parameters != null && parameters.length > 0) {
      List<Expression> arguments=null;
      if (call.getArguments() instanceof TupleExpression) {
        arguments=((TupleExpression)call.getArguments()).getExpressions();
      }
      if (arguments != null && !arguments.isEmpty()) {
        if (!methodNode.getDeclaringClass().equals(getPerceivedDeclaringType())) {
          List<Expression> categoryMethodArguments=new ArrayList<>(arguments.size() + 1);
          categoryMethodArguments.add(new ClassExpression(declaringType));
          categoryMethodArguments.addAll(arguments);
          arguments=categoryMethodArguments;
        }
        for (int i=0, n=parameters.length; i < n; i+=1) {
          List<AnnotationNode> annotations=parameters[i].getAnnotations();
          if (annotations != null && !annotations.isEmpty()) {
            for (            AnnotationNode annotation : annotations) {
              if (annotation.getClassNode().getName().equals(DELEGATES_TO.getName()) && i < arguments.size() && arguments.get(i) instanceof ClosureExpression) {
                ClosureExpression closure=(ClosureExpression)arguments.get(i);
                CompilerConfiguration config=enclosingModule.getUnit().getConfig();
                Expression delegatesToType=annotation.getMember("String_Node_Str");
                Expression delegatesToValue=annotation.getMember("String_Node_Str");
                Expression delegatesToTarget=annotation.getMember("String_Node_Str");
                Expression delegatesToStrategy=annotation.getMember("String_Node_Str");
                Expression delegatesToGenericTypeIndex=annotation.getMember("String_Node_Str");
                String typeName=null;
                Integer strategy=null, generics=null;
                if (delegatesToType != null) {
                  typeName=(String)evaluateExpression(castX(STRING_CLASS_NODE,delegatesToType),config);
                }
                if (delegatesToStrategy != null) {
                  strategy=(Integer)evaluateExpression(castX(INTEGER_CLASS_NODE,delegatesToStrategy),config);
                }
                if (delegatesToGenericTypeIndex != null) {
                  generics=(Integer)evaluateExpression(castX(INTEGER_CLASS_NODE,delegatesToGenericTypeIndex),config);
                }
                if (delegatesToValue instanceof ClassExpression && !delegatesToValue.getType().getName().equals("String_Node_Str")) {
                  addDelegatesToClosure(closure,delegatesToValue.getType(),strategy);
                }
 else                 if (typeName != null && !typeName.isEmpty()) {
                  CompilationUnit compilationUnit=null;
                  ClassNode[] resolved=parseClassNodesFromString(typeName,enclosingModule.getContext(),compilationUnit,methodNode,delegatesToType);
                  addDelegatesToClosure(closure,resolved[0],strategy);
                }
 else                 if (delegatesToValue == null || (delegatesToValue instanceof ClassExpression && delegatesToValue.getType().getName().equals("String_Node_Str"))) {
                  int j=indexOfDelegatesToTarget(parameters,(String)evaluateExpression(castX(STRING_CLASS_NODE,delegatesToTarget),config),config);
                  if (j >= 0 && j < arguments.size()) {
                    Expression target=arguments.get(j);
                    ClassNode targetType=target.getType();
                    if (generics != null && generics >= 0 && targetType.isUsingGenerics()) {
                      targetType.getGenericsTypes()[generics].getType();
                    }
                    addDelegatesToClosure(closure,targetType,strategy);
                  }
                }
              }
            }
          }
        }
        if (delegatesTo == null) {
          if (arguments.get(0) instanceof ClosureExpression && methodNode.getName().matches("String_Node_Str") && methodNode.getDeclaringClass().getName().equals("String_Node_Str")) {
            addDelegatesToClosure((ClosureExpression)arguments.get(0),methodNode.getDeclaringClass(),Closure.OWNER_FIRST);
          }
 else           if (arguments.size() > 1 && arguments.get(1) instanceof ClosureExpression && methodNode.getName().matches("String_Node_Str") && DGM_CLASS_NODE.equals(methodNode.getDeclaringClass())) {
            addDelegatesToClosure((ClosureExpression)arguments.get(1),declaringType,Closure.DELEGATE_FIRST);
          }
        }
      }
    }
  }
  if (delegatesTo == null) {
    delegatesTo=Collections.emptyMap();
  }
}