Program: 185348
Project: 185348
Buggy source:
/** 
 * Looks for a name within an object expression. It is either in the hierarchy, it is in the variable scope, or it is unknown.
 */
protected TypeLookupResult findTypeForNameWithKnownObjectExpression(String name,ClassNode type,ClassNode declaringType,VariableScope scope,TypeConfidence confidence,boolean isStaticObjectExpression,boolean isPrimaryExpression,boolean isLhsExpression){
  TypeConfidence confidence0=confidence;
  boolean isFieldAccessDirect=(isThisObjectExpression(scope) ? scope.isFieldAccessDirect() : false);
  ASTNode declaration=findDeclaration(name,declaringType,isLhsExpression,isStaticObjectExpression,isFieldAccessDirect,scope.getMethodCallArgumentTypes());
  ClassNode realDeclaringType;
  VariableInfo variableInfo;
  if (declaration != null) {
    type=getTypeFromDeclaration(declaration,declaringType);
    realDeclaringType=getDeclaringTypeFromDeclaration(declaration,declaringType);
  }
 else   if ("String_Node_Str".equals(name)) {
    declaration=type=realDeclaringType=declaringType.getGenericsTypes()[0].getType();
  }
 else   if (isPrimaryExpression && (variableInfo=scope.lookupName(name)) != null) {
    type=variableInfo.type;
    realDeclaringType=variableInfo.declaringType;
    declaration=findDeclaration(name,realDeclaringType,isLhsExpression,isStaticObjectExpression,false,scope.getMethodCallArgumentTypes());
    if (declaration == null) {
      declaration=variableInfo.declaringType;
    }
  }
 else   if ("String_Node_Str".equals(name)) {
    realDeclaringType=VariableScope.CLOSURE_CLASS_NODE;
    declaration=realDeclaringType.getMethods("String_Node_Str").get(0);
  }
 else {
    realDeclaringType=declaringType;
    confidence=TypeConfidence.UNKNOWN;
  }
  if (declaration != null) {
    if (!VariableScope.CLASS_CLASS_NODE.equals(realDeclaringType) && !VariableScope.CLASS_CLASS_NODE.equals(type)) {
      if (declaration instanceof FieldNode) {
        if (isStaticObjectExpression && !((FieldNode)declaration).isStatic()) {
          confidence=TypeConfidence.UNKNOWN;
        }
      }
 else       if (declaration instanceof PropertyNode) {
        FieldNode underlyingField=((PropertyNode)declaration).getField();
        if (underlyingField != null) {
          if (isStaticObjectExpression && !underlyingField.isStatic()) {
            confidence=TypeConfidence.UNKNOWN;
          }
        }
 else         if (isStaticObjectExpression && !((PropertyNode)declaration).isStatic()) {
          confidence=TypeConfidence.UNKNOWN;
        }
      }
 else       if (declaration instanceof MethodNode) {
        if (isStaticObjectExpression && !((MethodNode)declaration).isStatic()) {
          confidence=TypeConfidence.UNKNOWN;
        }
 else         if (isLooseMatch(scope.getMethodCallArgumentTypes(),((MethodNode)declaration).getParameters())) {
          confidence=TypeConfidence.LOOSELY_INFERRED;
        }
      }
    }
 else     if (VariableScope.CLASS_CLASS_NODE.equals(realDeclaringType) && declaration instanceof MethodNode) {
      if (isStaticObjectExpression && !((MethodNode)declaration).isStatic() && isLooseMatch(scope.getMethodCallArgumentTypes(),((MethodNode)declaration).getParameters())) {
        confidence=TypeConfidence.UNKNOWN;
      }
    }
  }
  if (confidence == TypeConfidence.UNKNOWN && VariableScope.CLASS_CLASS_NODE.equals(realDeclaringType) && realDeclaringType.isUsingGenerics()) {
    ClassNode typeParam=realDeclaringType.getGenericsTypes()[0].getType();
    if (!VariableScope.CLASS_CLASS_NODE.equals(typeParam) && !VariableScope.OBJECT_CLASS_NODE.equals(typeParam)) {
      return findTypeForNameWithKnownObjectExpression(name,type,typeParam,scope,confidence0,isStaticObjectExpression,isPrimaryExpression,isLhsExpression);
    }
  }
  return new TypeLookupResult(type,realDeclaringType,declaration,confidence,scope);
}

Fixed version (ground truth):
/** 
 * Looks for a name within an object expression. It is either in the hierarchy, it is in the variable scope, or it is unknown.
 */
protected TypeLookupResult findTypeForNameWithKnownObjectExpression(String name,ClassNode type,ClassNode declaringType,VariableScope scope,TypeConfidence confidence,boolean isStaticObjectExpression,boolean isPrimaryExpression,boolean isLhsExpression){
  TypeConfidence confidence0=confidence;
  boolean isFieldAccessDirect=(isThisObjectExpression(scope) ? scope.isFieldAccessDirect() : false);
  ASTNode declaration=findDeclaration(name,declaringType,isLhsExpression,isStaticObjectExpression,isFieldAccessDirect,scope.getMethodCallArgumentTypes());
  ClassNode realDeclaringType;
  VariableInfo variableInfo;
  if (declaration != null) {
    type=getTypeFromDeclaration(declaration,declaringType);
    realDeclaringType=getDeclaringTypeFromDeclaration(declaration,declaringType);
  }
 else   if ("String_Node_Str".equals(name)) {
    declaration=type=realDeclaringType=declaringType.getGenericsTypes()[0].getType();
  }
 else   if (isPrimaryExpression && (variableInfo=scope.lookupName(name)) != null) {
    type=variableInfo.type;
    realDeclaringType=variableInfo.declaringType;
    declaration=findDeclaration(name,realDeclaringType,isLhsExpression,isStaticObjectExpression,false,scope.getMethodCallArgumentTypes());
    if (declaration == null) {
      declaration=variableInfo.declaringType;
    }
  }
 else   if ("String_Node_Str".equals(name)) {
    realDeclaringType=VariableScope.CLOSURE_CLASS_NODE;
    declaration=realDeclaringType.getMethods("String_Node_Str").get(0);
  }
 else {
    realDeclaringType=declaringType;
    confidence=TypeConfidence.UNKNOWN;
  }
  if (declaration != null) {
    if (!VariableScope.CLASS_CLASS_NODE.equals(realDeclaringType) && !VariableScope.CLASS_CLASS_NODE.equals(type)) {
      if (declaration instanceof FieldNode) {
        if (isStaticObjectExpression && !((FieldNode)declaration).isStatic()) {
          confidence=TypeConfidence.UNKNOWN;
        }
      }
 else       if (declaration instanceof PropertyNode) {
        FieldNode underlyingField=((PropertyNode)declaration).getField();
        if (underlyingField != null) {
          if (isStaticObjectExpression && !underlyingField.isStatic()) {
            confidence=TypeConfidence.UNKNOWN;
          }
        }
 else         if (isStaticObjectExpression && !((PropertyNode)declaration).isStatic()) {
          confidence=TypeConfidence.UNKNOWN;
        }
      }
 else       if (declaration instanceof MethodNode) {
        if (isStaticObjectExpression && !((MethodNode)declaration).isStatic()) {
          confidence=TypeConfidence.UNKNOWN;
        }
 else         if (isLooseMatch(scope.getMethodCallArgumentTypes(),((MethodNode)declaration).getParameters())) {
          confidence=TypeConfidence.LOOSELY_INFERRED;
        }
      }
    }
 else     if (VariableScope.CLASS_CLASS_NODE.equals(realDeclaringType) && declaration instanceof MethodNode) {
      if (isStaticObjectExpression && !((MethodNode)declaration).isStatic() && isLooseMatch(scope.getMethodCallArgumentTypes(),((MethodNode)declaration).getParameters())) {
        confidence=TypeConfidence.UNKNOWN;
      }
    }
  }
  if (confidence == TypeConfidence.UNKNOWN && VariableScope.CLASS_CLASS_NODE.equals(declaringType) && declaringType.isUsingGenerics()) {
    ClassNode typeParam=declaringType.getGenericsTypes()[0].getType();
    if (!VariableScope.CLASS_CLASS_NODE.equals(typeParam) && !VariableScope.OBJECT_CLASS_NODE.equals(typeParam)) {
      return findTypeForNameWithKnownObjectExpression(name,type,typeParam,scope,confidence0,isStaticObjectExpression,isPrimaryExpression,isLhsExpression);
    }
  }
  return new TypeLookupResult(type,realDeclaringType,declaration,confidence,scope);
}