Program: 91176
Project: 91176
Buggy source:
@Override public boolean filter(T elem) throws Exception {
  int elemParameterCount=0;
  Type[] genericParameterTypes=null;
  Class<?> declaringClass=null;
  if (elem instanceof Method) {
    elemParameterCount=((Method)elem).getParameterTypes().length;
    genericParameterTypes=((Method)elem).getGenericParameterTypes();
    declaringClass=((Method)elem).getDeclaringClass();
  }
 else   if (elem instanceof Constructor) {
    elemParameterCount=((Constructor<?>)elem).getParameterTypes().length;
    genericParameterTypes=((Constructor<?>)elem).getGenericParameterTypes();
    declaringClass=((Constructor<?>)elem).getDeclaringClass();
  }
 else {
    return false;
  }
  Object equivalentMethod=null;
  sd=(SymbolType)expression.getScope().getSymbolData();
  if (sd == null) {
    expression.getScope().accept(typeResolver,ctx);
    sd=(SymbolType)expression.getScope().getSymbolData();
    if (!expression.getIdentifier().equals("String_Node_Str")) {
      if (methodsArray == null) {
        Set<Method> methods=MethodInspector.getVisibleMethods(sd.getClazz(),thisClass);
        methodsArray=new Method[methods.size()];
        methods.toArray(methodsArray);
        ExecutableSorter sorter=new ExecutableSorter();
        List<Method> sortedMethods=sorter.sort(methodsArray,null);
        sortedMethods.toArray(methodsArray);
      }
      ArrayFilter<Method> filter=new ArrayFilter<Method>(methodsArray);
      filter.appendPredicate(new MethodsByNamePredicate(expression.getIdentifier()));
      methodCallCandidates=filter.filter();
    }
  }
  boolean found=false;
  if (!expression.getIdentifier().equals("String_Node_Str")) {
    Iterator<Method> it=methodCallCandidates.iterator();
    while (it.hasNext() && !found) {
      Method md=it.next();
      int mdParameterCount=md.getParameterTypes().length;
      Map<String,SymbolType> typeMapping=getTypeMapping();
      FunctionalGenericsBuilder<MethodReferenceExpr> builder=new FunctionalGenericsBuilder<MethodReferenceExpr>(md,typeResolver,typeMapping);
      builder.build(expression);
      SymbolType[] args=builder.getArgs();
      if (!Modifier.isStatic(md.getModifiers())) {
        if (mdParameterCount == elemParameterCount - 1) {
          SymbolType[] genericArgs=new SymbolType[genericParameterTypes.length];
          boolean allAreGenerics=true;
          for (int i=0; i < genericParameterTypes.length && allAreGenerics; i++) {
            if (genericParameterTypes[i] instanceof TypeVariable<?>) {
              TypeVariable<?> td=(TypeVariable<?>)genericParameterTypes[i];
              genericArgs[i]=typeMapping.get(td.getName());
              allAreGenerics=genericArgs[i] != null;
            }
 else {
              allAreGenerics=false;
            }
          }
          if (allAreGenerics) {
            setTypeArgs(genericArgs);
            found=super.filter(elem);
          }
 else {
            SymbolType[] staticArgs=new SymbolType[args.length + 1];
            for (int i=0; i < args.length; i++) {
              staticArgs[i + 1]=args[i];
            }
            staticArgs[0]=(SymbolType)sd;
            args=staticArgs;
            setTypeArgs(args);
            found=super.filter(elem);
          }
        }
 else {
          Expression scope=expression.getScope();
          SymbolType stype=(SymbolType)scope.getSymbolData();
          boolean isField=stype.getField() != null;
          boolean isVariable=false;
          boolean isSuper=scope instanceof SuperExpr;
          if (!isField && !isSuper) {
            String name=scope.toString();
            isVariable=(symTable.findSymbol(name,ReferenceType.VARIABLE) != null);
          }
          if ((isField || isVariable || isSuper) && mdParameterCount == elemParameterCount) {
            setTypeArgs(args);
            found=super.filter(elem);
          }
        }
      }
 else       if (mdParameterCount == elemParameterCount) {
        setTypeArgs(args);
        found=super.filter(elem);
      }
      if (found) {
        equivalentMethod=md;
      }
    }
  }
 else {
    Constructor<?>[] constructors=sd.getClazz().getDeclaredConstructors();
    for (int i=0; i < constructors.length && !found; i++) {
      FunctionalGenericsBuilder<MethodReferenceExpr> builder=new FunctionalGenericsBuilder<MethodReferenceExpr>(constructors[i],typeResolver,getTypeMapping());
      builder.build(expression);
      SymbolType[] args=builder.getArgs();
      setTypeArgs(args);
      found=super.filter(elem);
      if (found) {
        equivalentMethod=constructors[i];
      }
    }
  }
  if (found && elem instanceof Method) {
    Map<String,SymbolType> mapping=getTypeMapping();
    SymbolType realResultType=null;
    if (equivalentMethod instanceof Method) {
      realResultType=SymbolType.valueOf((Method)equivalentMethod,mapping);
      java.lang.reflect.Type genericReturnType=((Method)elem).getGenericReturnType();
      resolveTypeMapping(genericReturnType,realResultType,mapping);
    }
    realResultType=SymbolType.valueOf(declaringClass,mapping);
    expression.setSymbolData(realResultType);
    SymbolType st=SymbolType.valueOf((Method)elem,mapping);
    expression.setReferencedMethodSymbolData(st);
    expression.setReferencedArgsSymbolData(getTypeArgs());
  }
  return found;
}

Fixed version (ground truth):
@Override public boolean filter(T elem) throws Exception {
  int elemParameterCount=0;
  Type[] genericParameterTypes=null;
  Class<?> declaringClass=null;
  Map<String,SymbolType> typeMapping=getTypeMapping();
  FunctionalGenericsBuilder<MethodReferenceExpr> builder=null;
  if (elem instanceof Method) {
    elemParameterCount=((Method)elem).getParameterTypes().length;
    genericParameterTypes=((Method)elem).getGenericParameterTypes();
    declaringClass=((Method)elem).getDeclaringClass();
    builder=new FunctionalGenericsBuilder<>(((Method)elem),typeResolver,typeMapping);
  }
 else   if (elem instanceof Constructor) {
    elemParameterCount=((Constructor<?>)elem).getParameterTypes().length;
    genericParameterTypes=((Constructor<?>)elem).getGenericParameterTypes();
    declaringClass=((Constructor<?>)elem).getDeclaringClass();
    builder=new FunctionalGenericsBuilder<>(((Constructor<?>)elem),typeResolver,typeMapping);
  }
 else {
    return false;
  }
  builder.build(expression);
  Object equivalentMethod=null;
  sd=(SymbolType)expression.getScope().getSymbolData();
  if (sd == null) {
    expression.getScope().accept(typeResolver,ctx);
    sd=(SymbolType)expression.getScope().getSymbolData();
    if (!expression.getIdentifier().equals("String_Node_Str")) {
      if (methodsArray == null) {
        Set<Method> methods=MethodInspector.getVisibleMethods(sd.getClazz(),thisClass);
        methodsArray=new Method[methods.size()];
        methods.toArray(methodsArray);
        ExecutableSorter sorter=new ExecutableSorter();
        List<Method> sortedMethods=sorter.sort(methodsArray,null);
        sortedMethods.toArray(methodsArray);
      }
      ArrayFilter<Method> filter=new ArrayFilter<Method>(methodsArray);
      filter.appendPredicate(new MethodsByNamePredicate(expression.getIdentifier()));
      methodCallCandidates=filter.filter();
    }
  }
  boolean found=false;
  if (!expression.getIdentifier().equals("String_Node_Str")) {
    Iterator<Method> it=methodCallCandidates.iterator();
    SymbolType[] args=builder.getArgs();
    while (it.hasNext() && !found) {
      Method md=it.next();
      int mdParameterCount=md.getParameterTypes().length;
      if (!Modifier.isStatic(md.getModifiers())) {
        if (mdParameterCount == elemParameterCount - 1) {
          SymbolType[] genericArgs=new SymbolType[genericParameterTypes.length];
          boolean allAreGenerics=true;
          for (int i=0; i < genericParameterTypes.length && allAreGenerics; i++) {
            if (genericParameterTypes[i] instanceof TypeVariable<?>) {
              TypeVariable<?> td=(TypeVariable<?>)genericParameterTypes[i];
              genericArgs[i]=typeMapping.get(td.getName());
              allAreGenerics=genericArgs[i] != null;
            }
 else {
              allAreGenerics=false;
            }
          }
          if (allAreGenerics) {
            setTypeArgs(genericArgs);
            found=super.filter(elem);
          }
 else {
            SymbolType[] staticArgs=new SymbolType[args.length + 1];
            for (int i=0; i < args.length; i++) {
              staticArgs[i + 1]=args[i];
            }
            staticArgs[0]=(SymbolType)sd;
            args=staticArgs;
            setTypeArgs(args);
            found=super.filter(elem);
          }
        }
 else {
          Expression scope=expression.getScope();
          SymbolType stype=(SymbolType)scope.getSymbolData();
          boolean isField=stype.getField() != null;
          boolean isVariable=false;
          boolean isSuper=scope instanceof SuperExpr;
          if (!isField && !isSuper) {
            String name=scope.toString();
            isVariable=(symTable.findSymbol(name,ReferenceType.VARIABLE) != null);
          }
          if ((isField || isVariable || isSuper) && mdParameterCount == elemParameterCount) {
            setTypeArgs(args);
            found=super.filter(elem);
          }
        }
      }
 else       if (mdParameterCount == elemParameterCount) {
        setTypeArgs(args);
        found=super.filter(elem);
      }
      if (found) {
        equivalentMethod=md;
      }
    }
  }
 else {
    SymbolType[] args=builder.getArgs();
    setTypeArgs(args);
    found=super.filter(elem);
  }
  if (found && elem instanceof Method) {
    Map<String,SymbolType> mapping=getTypeMapping();
    SymbolType realResultType=null;
    if (equivalentMethod != null && equivalentMethod instanceof Method) {
      realResultType=SymbolType.valueOf((Method)equivalentMethod,mapping);
      java.lang.reflect.Type genericReturnType=((Method)elem).getGenericReturnType();
      resolveTypeMapping(genericReturnType,realResultType,mapping);
    }
    realResultType=SymbolType.valueOf(declaringClass,mapping);
    expression.setSymbolData(realResultType);
    SymbolType st=SymbolType.valueOf((Method)elem,mapping);
    expression.setReferencedMethodSymbolData(st);
    expression.setReferencedArgsSymbolData(getTypeArgs());
  }
  return found;
}