Program: 185488
Project: 185488
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 && !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 (((MethodNode)declaration).getParameters().length != scope.getMethodCallNumberOfArguments()) {
          confidence=TypeConfidence.LOOSELY_INFERRED;
        }
      }
    }
  }
  if (TypeConfidence.UNKNOWN.equals(confidence) && VariableScope.CLASS_CLASS_NODE.equals(realDeclaringType)) {
    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 && !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;
      }
    }
  }
  if (TypeConfidence.UNKNOWN.equals(confidence) && VariableScope.CLASS_CLASS_NODE.equals(realDeclaringType)) {
    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);
}