Program: 185276
Project: 185276
Buggy source:
private ClassNode[] inferClosureParamTypes(ClosureExpression node,VariableScope scope){
  if (node.getParameters() == null) {
    return ClassNode.EMPTY_ARRAY;
  }
  ClassNode primaryType=null;
  ClassNode[] inferredTypes=new ClassNode[node.isParameterSpecified() ? node.getParameters().length : 1];
  VariableScope.CallAndType cat=scope.getEnclosingMethodCallExpression();
  if (cat != null && cat.declaration instanceof MethodNode) {
    MethodNode methodNode=(MethodNode)cat.declaration;
    Parameter methodParam=findTargetParameter(node,cat.call,methodNode,!methodNode.getDeclaringClass().equals(cat.getPerceivedDeclaringType()));
    if (methodParam != null) {
      if (VariableScope.CLOSURE_CLASS_NODE.equals(methodParam.getType())) {
        GroovyUtils.getAnnotations(methodParam,VariableScope.CLOSURE_PARAMS.getName()).findFirst().ifPresent(cp -> {
          SourceUnit sourceUnit=enclosingModule.getContext();
          try {
            @SuppressWarnings("String_Node_Str") Class<? extends ClosureSignatureHint> hint=(Class<? extends ClosureSignatureHint>)StaticTypeCheckingSupport.evaluateExpression(GeneralUtils.castX(VariableScope.CLASS_CLASS_NODE,cp.getMember("String_Node_Str")),sourceUnit.getConfiguration());
            String[] opts=(String[])StaticTypeCheckingSupport.evaluateExpression(GeneralUtils.castX(VariableScope.STRING_CLASS_NODE.makeArray(),cp.getMember("String_Node_Str")),sourceUnit.getConfiguration());
            List<ClassNode[]> sigs=hint.newInstance().getClosureSignatures(methodNode,sourceUnit,resolver.compilationUnit,opts,cat.call);
            if (isNotEmpty(sigs)) {
              for (              ClassNode[] sig : sigs) {
                if (sig.length == inferredTypes.length) {
                  GenericsType[] generics=getMethodCallGenericsTypes(cat.call);
                  List<ClassNode> arguments=GroovyUtils.getParameterTypes(methodNode.getParameters());
                  GenericsMapper map=GenericsMapper.gatherGenerics(arguments,cat.declaringType,methodNode.getOriginal(),generics);
                  for (int i=0, n=sig.length; i < n; i+=1) {
                    inferredTypes[i]=VariableScope.resolveTypeParameterization(map,sig[i]);
                  }
                  break;
                }
              }
            }
          }
 catch (          Exception e) {
            log(e,"String_Node_Str",methodNode.getTypeDescriptor());
          }
        }
);
      }
      if (inferredTypes[0] == null) {
        primaryType=methodParam.getType();
        if (GenericsMapper.isVargs(methodNode.getParameters()) && DefaultGroovyMethods.last(methodNode.getParameters()) == methodParam) {
          primaryType=primaryType.getComponentType();
        }
      }
    }
  }
 else   if (!completeExpressionStack.isEmpty() && completeExpressionStack.getLast() instanceof CastExpression && ((CastExpression)completeExpressionStack.getLast()).getExpression() == node) {
    primaryType=((CastExpression)completeExpressionStack.getLast()).getType();
  }
 else   if (enclosingAssignment != null && enclosingAssignment.getRightExpression() == node) {
    primaryType=enclosingAssignment.getLeftExpression().getType();
  }
  if (inferredTypes[0] == null) {
    int i=0;
    MethodNode sam;
    if (primaryType != null && (sam=ClassHelper.findSAM(primaryType)) != null) {
      for (      ClassNode t : GroovyUtils.getParameterTypes(sam.getParameters())) {
        if (i == inferredTypes.length)         break;
        inferredTypes[i++]=t;
      }
    }
    Arrays.fill(inferredTypes,i,inferredTypes.length,VariableScope.OBJECT_CLASS_NODE);
  }
  return inferredTypes;
}

Fixed version (ground truth):
private ClassNode[] inferClosureParamTypes(ClosureExpression node,VariableScope scope){
  if (node.getParameters() == null) {
    return ClassNode.EMPTY_ARRAY;
  }
  ClassNode primaryType=null;
  ClassNode[] inferredTypes=new ClassNode[node.isParameterSpecified() ? node.getParameters().length : 1];
  VariableScope.CallAndType cat=scope.getEnclosingMethodCallExpression();
  if (cat != null && cat.declaration instanceof MethodNode) {
    MethodNode methodNode=(MethodNode)cat.declaration;
    Parameter methodParam=findTargetParameter(node,cat.call,methodNode,!methodNode.getDeclaringClass().equals(cat.getPerceivedDeclaringType()));
    if (methodParam != null) {
      if (VariableScope.CLOSURE_CLASS_NODE.equals(methodParam.getType())) {
        GroovyUtils.getAnnotations(methodParam,VariableScope.CLOSURE_PARAMS.getName()).findFirst().ifPresent(cp -> {
          SourceUnit sourceUnit=enclosingModule.getContext();
          try {
            @SuppressWarnings("String_Node_Str") Class<? extends ClosureSignatureHint> hint=(Class<? extends ClosureSignatureHint>)StaticTypeCheckingSupport.evaluateExpression(GeneralUtils.castX(VariableScope.CLASS_CLASS_NODE,cp.getMember("String_Node_Str")),sourceUnit.getConfiguration());
            String[] opts=(String[])(cp.getMember("String_Node_Str") == null ? ClosureParams.class.getMethod("String_Node_Str").getDefaultValue() : StaticTypeCheckingSupport.evaluateExpression(GeneralUtils.castX(VariableScope.STRING_CLASS_NODE.makeArray(),cp.getMember("String_Node_Str")),sourceUnit.getConfiguration()));
            List<ClassNode[]> sigs=hint.newInstance().getClosureSignatures(methodNode,sourceUnit,resolver.compilationUnit,opts,cat.call);
            if (isNotEmpty(sigs)) {
              for (              ClassNode[] sig : sigs) {
                if (sig.length == inferredTypes.length) {
                  GenericsType[] generics=getMethodCallGenericsTypes(cat.call);
                  List<ClassNode> arguments=GroovyUtils.getParameterTypes(methodNode.getParameters());
                  GenericsMapper map=GenericsMapper.gatherGenerics(arguments,cat.declaringType,methodNode.getOriginal(),generics);
                  for (int i=0, n=sig.length; i < n; i+=1) {
                    inferredTypes[i]=VariableScope.resolveTypeParameterization(map,sig[i]);
                  }
                  break;
                }
              }
            }
          }
 catch (          Exception e) {
            log(e,"String_Node_Str",methodNode.getTypeDescriptor());
          }
        }
);
      }
      if (inferredTypes[0] == null) {
        primaryType=methodParam.getType();
        if (GenericsMapper.isVargs(methodNode.getParameters()) && DefaultGroovyMethods.last(methodNode.getParameters()) == methodParam) {
          primaryType=primaryType.getComponentType();
        }
      }
    }
  }
 else   if (!completeExpressionStack.isEmpty() && completeExpressionStack.getLast() instanceof CastExpression && ((CastExpression)completeExpressionStack.getLast()).getExpression() == node) {
    primaryType=((CastExpression)completeExpressionStack.getLast()).getType();
  }
 else   if (enclosingAssignment != null && enclosingAssignment.getRightExpression() == node) {
    primaryType=enclosingAssignment.getLeftExpression().getType();
  }
  if (inferredTypes[0] == null) {
    int i=0;
    MethodNode sam;
    if (primaryType != null && (sam=ClassHelper.findSAM(primaryType)) != null) {
      for (      ClassNode t : GroovyUtils.getParameterTypes(sam.getParameters())) {
        if (i == inferredTypes.length)         break;
        inferredTypes[i++]=t;
      }
    }
    Arrays.fill(inferredTypes,i,inferredTypes.length,VariableScope.OBJECT_CLASS_NODE);
  }
  return inferredTypes;
}