Program: 185521
Project: 185521
Buggy source:
protected TypeLookupResult findType(Expression node,ClassNode declaringType,VariableScope scope,TypeConfidence confidence,boolean isStaticObjectExpression,boolean isPrimaryExpression){
  MethodNode target;
  if (scope.isMethodCall() && (target=getMethodTarget(node)) != null) {
    return new TypeLookupResult(target.getReturnType(),target.getDeclaringClass(),target,confidence,scope);
  }
  if (node instanceof VariableExpression) {
    return findTypeForVariable((VariableExpression)node,scope,confidence,declaringType);
  }
  if (!isPrimaryExpression && node instanceof ConstantExpression && scope.getEnclosingNode() instanceof AttributeExpression) {
    ClassNode clazz=!isStaticObjectExpression ? declaringType : declaringType.getGenericsTypes()[0].getType();
    FieldNode field=clazz.getDeclaredField(node.getText());
    if (isCompatible(field,isStaticObjectExpression)) {
      return new TypeLookupResult(field.getType(),clazz,field,TypeConfidence.EXACT,scope);
    }
 else {
      return new TypeLookupResult(VariableScope.VOID_CLASS_NODE,clazz,null,TypeConfidence.UNKNOWN,scope);
    }
  }
  ClassNode nodeType=node.getType();
  if ((!isPrimaryExpression || scope.isMethodCall()) && node instanceof ConstantExpression) {
    return findTypeForNameWithKnownObjectExpression(node.getText(),nodeType,declaringType,scope,confidence,isStaticObjectExpression,isPrimaryExpression,(scope.getWormhole().remove("String_Node_Str") == node));
  }
  if (node instanceof ConstantExpression) {
    ConstantExpression cexp=(ConstantExpression)node;
    if (cexp.isNullExpression()) {
      return new TypeLookupResult(VariableScope.VOID_CLASS_NODE,null,null,confidence,scope);
    }
 else     if (cexp.isTrueExpression() || cexp.isFalseExpression()) {
      return new TypeLookupResult(VariableScope.BOOLEAN_CLASS_NODE,null,null,confidence,scope);
    }
 else     if (cexp.isEmptyStringExpression() || VariableScope.STRING_CLASS_NODE.equals(nodeType)) {
      return new TypeLookupResult(VariableScope.STRING_CLASS_NODE,null,node,confidence,scope);
    }
 else     if (ClassHelper.isNumberType(nodeType) || VariableScope.BIG_DECIMAL_CLASS.equals(nodeType) || VariableScope.BIG_INTEGER_CLASS.equals(nodeType)) {
      return new TypeLookupResult(ClassHelper.isPrimitiveType(nodeType) ? ClassHelper.getWrapper(nodeType) : nodeType,null,null,confidence,scope);
    }
 else {
      return new TypeLookupResult(nodeType,null,null,TypeConfidence.UNKNOWN,scope);
    }
  }
 else   if (node instanceof BooleanExpression) {
    return new TypeLookupResult(VariableScope.BOOLEAN_CLASS_NODE,null,null,confidence,scope);
  }
 else   if (node instanceof GStringExpression) {
    return new TypeLookupResult(VariableScope.STRING_CLASS_NODE,null,null,confidence,scope);
  }
 else   if (node instanceof BitwiseNegationExpression) {
    ClassNode type=((BitwiseNegationExpression)node).getExpression().getType();
    if (VariableScope.STRING_CLASS_NODE.equals(type)) {
      return new TypeLookupResult(VariableScope.PATTERN_CLASS_NODE,null,null,confidence,scope);
    }
    return new TypeLookupResult(type,null,null,confidence,scope);
  }
 else   if (node instanceof ClosureExpression && VariableScope.isPlainClosure(nodeType)) {
    ClassNode returnType=(ClassNode)node.getNodeMetaData("String_Node_Str");
    if (returnType != null && !VariableScope.isVoidOrObject(returnType))     GroovyUtils.updateClosureWithInferredTypes(nodeType,returnType,((ClosureExpression)node).getParameters());
  }
 else   if (node instanceof ClassExpression) {
    ClassNode classType=VariableScope.newClassClassNode(node.getType());
    classType.setSourcePosition(node);
    return new TypeLookupResult(classType,null,node.getType(),TypeConfidence.EXACT,scope);
  }
 else   if (node instanceof ConstructorCallExpression) {
    ConstructorCallExpression constructorCall=(ConstructorCallExpression)node;
    MethodNode constructorDecl=scope.getEnclosingMethodDeclaration();
    if (constructorCall.isThisCall()) {
      declaringType=constructorDecl != null ? constructorDecl.getDeclaringClass() : scope.getEnclosingTypeDeclaration();
    }
 else     if (constructorCall.isSuperCall()) {
      declaringType=constructorDecl != null ? constructorDecl.getDeclaringClass().getUnresolvedSuperClass() : scope.getEnclosingTypeDeclaration();
    }
    List<ConstructorNode> declaredConstructors=declaringType.getDeclaredConstructors();
    if (constructorCall.getArguments() instanceof ArgumentListExpression && declaredConstructors.size() > 1) {
      List<ConstructorNode> looseMatches=new ArrayList<ConstructorNode>();
      List<ClassNode> callTypes=scope.getMethodCallArgumentTypes();
      for (      ConstructorNode ctor : declaredConstructors) {
        if (callTypes.size() == ctor.getParameters().length) {
          if (Boolean.TRUE.equals(isTypeCompatible(callTypes,ctor.getParameters()))) {
            return new TypeLookupResult(nodeType,declaringType,ctor,confidence,scope);
          }
          looseMatches.add(ctor);
        }
      }
      if (!looseMatches.isEmpty()) {
        declaredConstructors=looseMatches;
      }
    }
    ASTNode declaration=!declaredConstructors.isEmpty() ? declaredConstructors.get(0) : declaringType;
    return new TypeLookupResult(nodeType,declaringType,declaration,confidence,scope);
  }
 else   if (node instanceof StaticMethodCallExpression) {
    String methodName=((StaticMethodCallExpression)node).getMethod();
    ClassNode ownerType=((StaticMethodCallExpression)node).getOwnerType();
    List<MethodNode> candidates=new LinkedList<MethodNode>();
    if (!ownerType.isInterface()) {
      candidates.addAll(ownerType.getMethods(methodName));
    }
 else {
      LinkedHashSet<ClassNode> faces=new LinkedHashSet<ClassNode>();
      VariableScope.findAllInterfaces(ownerType,faces,false);
      for (      ClassNode face : faces) {
        candidates.addAll(face.getMethods(methodName));
      }
    }
    for (Iterator<MethodNode> it=candidates.iterator(); it.hasNext(); ) {
      if (!it.next().isStatic())       it.remove();
    }
    if (!candidates.isEmpty()) {
      MethodNode closestMatch;
      if (scope.isMethodCall()) {
        closestMatch=findMethodDeclaration0(candidates,scope.getMethodCallArgumentTypes());
        confidence=TypeConfidence.INFERRED;
      }
 else {
        closestMatch=candidates.get(0);
        confidence=TypeConfidence.LOOSELY_INFERRED;
      }
      return new TypeLookupResult(closestMatch.getReturnType(),closestMatch.getDeclaringClass(),closestMatch,confidence,scope);
    }
  }
  if (!(node instanceof TupleExpression) && nodeType.equals(VariableScope.OBJECT_CLASS_NODE)) {
    confidence=TypeConfidence.UNKNOWN;
  }
  return new TypeLookupResult(nodeType,declaringType,null,confidence,scope);
}

Fixed version (ground truth):
protected TypeLookupResult findType(Expression node,ClassNode declaringType,VariableScope scope,TypeConfidence confidence,boolean isStaticObjectExpression,boolean isPrimaryExpression){
  MethodNode target;
  if (scope.isMethodCall() && (target=getMethodTarget(node)) != null) {
    return new TypeLookupResult(target.getReturnType(),target.getDeclaringClass(),target,confidence,scope);
  }
  if (node instanceof VariableExpression) {
    return findTypeForVariable((VariableExpression)node,scope,confidence,declaringType);
  }
 else   if (node instanceof ConstantExpression && isPrimaryExpression && scope.isMethodCall()) {
    VariableExpression expr=new VariableExpression(new DynamicVariable(node.getText(),false));
    TypeLookupResult result=findTypeForVariable(expr,scope,confidence,declaringType);
    if (isCompatible((AnnotatedNode)result.declaration,isStaticObjectExpression)) {
      return result;
    }
  }
  ClassNode nodeType=node.getType();
  if (node instanceof ConstantExpression) {
    if (!isPrimaryExpression) {
      if (scope.getEnclosingNode() instanceof AttributeExpression) {
        ClassNode clazz=!isStaticObjectExpression ? declaringType : declaringType.getGenericsTypes()[0].getType();
        FieldNode field=clazz.getDeclaredField(node.getText());
        if (isCompatible(field,isStaticObjectExpression)) {
          return new TypeLookupResult(field.getType(),clazz,field,TypeConfidence.EXACT,scope);
        }
 else {
          return new TypeLookupResult(VariableScope.VOID_CLASS_NODE,clazz,null,TypeConfidence.UNKNOWN,scope);
        }
      }
    }
    if (!isPrimaryExpression || scope.isMethodCall()) {
      return findTypeForNameWithKnownObjectExpression(node.getText(),nodeType,declaringType,scope,confidence,isStaticObjectExpression,isPrimaryExpression,(scope.getWormhole().remove("String_Node_Str") == node));
    }
    ConstantExpression cexp=(ConstantExpression)node;
    if (cexp.isNullExpression()) {
      return new TypeLookupResult(VariableScope.VOID_CLASS_NODE,null,null,confidence,scope);
    }
 else     if (cexp.isTrueExpression() || cexp.isFalseExpression()) {
      return new TypeLookupResult(VariableScope.BOOLEAN_CLASS_NODE,null,null,confidence,scope);
    }
 else     if (cexp.isEmptyStringExpression() || VariableScope.STRING_CLASS_NODE.equals(nodeType)) {
      return new TypeLookupResult(VariableScope.STRING_CLASS_NODE,null,node,confidence,scope);
    }
 else     if (ClassHelper.isNumberType(nodeType) || VariableScope.BIG_DECIMAL_CLASS.equals(nodeType) || VariableScope.BIG_INTEGER_CLASS.equals(nodeType)) {
      return new TypeLookupResult(ClassHelper.isPrimitiveType(nodeType) ? ClassHelper.getWrapper(nodeType) : nodeType,null,null,confidence,scope);
    }
 else {
      return new TypeLookupResult(nodeType,null,null,TypeConfidence.UNKNOWN,scope);
    }
  }
 else   if (node instanceof BooleanExpression) {
    return new TypeLookupResult(VariableScope.BOOLEAN_CLASS_NODE,null,null,confidence,scope);
  }
 else   if (node instanceof GStringExpression) {
    return new TypeLookupResult(VariableScope.STRING_CLASS_NODE,null,null,confidence,scope);
  }
 else   if (node instanceof BitwiseNegationExpression) {
    ClassNode type=((BitwiseNegationExpression)node).getExpression().getType();
    if (VariableScope.STRING_CLASS_NODE.equals(type)) {
      return new TypeLookupResult(VariableScope.PATTERN_CLASS_NODE,null,null,confidence,scope);
    }
    return new TypeLookupResult(type,null,null,confidence,scope);
  }
 else   if (node instanceof ClosureExpression && VariableScope.isPlainClosure(nodeType)) {
    ClassNode returnType=(ClassNode)node.getNodeMetaData("String_Node_Str");
    if (returnType != null && !VariableScope.isVoidOrObject(returnType))     GroovyUtils.updateClosureWithInferredTypes(nodeType,returnType,((ClosureExpression)node).getParameters());
  }
 else   if (node instanceof ClassExpression) {
    ClassNode classType=VariableScope.newClassClassNode(node.getType());
    classType.setSourcePosition(node);
    return new TypeLookupResult(classType,null,node.getType(),TypeConfidence.EXACT,scope);
  }
 else   if (node instanceof ConstructorCallExpression) {
    ConstructorCallExpression constructorCall=(ConstructorCallExpression)node;
    MethodNode constructorDecl=scope.getEnclosingMethodDeclaration();
    if (constructorCall.isThisCall()) {
      declaringType=constructorDecl != null ? constructorDecl.getDeclaringClass() : scope.getEnclosingTypeDeclaration();
    }
 else     if (constructorCall.isSuperCall()) {
      declaringType=constructorDecl != null ? constructorDecl.getDeclaringClass().getUnresolvedSuperClass() : scope.getEnclosingTypeDeclaration();
    }
    List<ConstructorNode> declaredConstructors=declaringType.getDeclaredConstructors();
    if (constructorCall.getArguments() instanceof ArgumentListExpression && declaredConstructors.size() > 1) {
      List<ConstructorNode> looseMatches=new ArrayList<ConstructorNode>();
      List<ClassNode> callTypes=scope.getMethodCallArgumentTypes();
      for (      ConstructorNode ctor : declaredConstructors) {
        if (callTypes.size() == ctor.getParameters().length) {
          if (Boolean.TRUE.equals(isTypeCompatible(callTypes,ctor.getParameters()))) {
            return new TypeLookupResult(nodeType,declaringType,ctor,confidence,scope);
          }
          looseMatches.add(ctor);
        }
      }
      if (!looseMatches.isEmpty()) {
        declaredConstructors=looseMatches;
      }
    }
    ASTNode declaration=!declaredConstructors.isEmpty() ? declaredConstructors.get(0) : declaringType;
    return new TypeLookupResult(nodeType,declaringType,declaration,confidence,scope);
  }
 else   if (node instanceof StaticMethodCallExpression) {
    String methodName=((StaticMethodCallExpression)node).getMethod();
    ClassNode ownerType=((StaticMethodCallExpression)node).getOwnerType();
    List<MethodNode> candidates=new LinkedList<MethodNode>();
    if (!ownerType.isInterface()) {
      candidates.addAll(ownerType.getMethods(methodName));
    }
 else {
      LinkedHashSet<ClassNode> faces=new LinkedHashSet<ClassNode>();
      VariableScope.findAllInterfaces(ownerType,faces,false);
      for (      ClassNode face : faces) {
        candidates.addAll(face.getMethods(methodName));
      }
    }
    for (Iterator<MethodNode> it=candidates.iterator(); it.hasNext(); ) {
      if (!it.next().isStatic())       it.remove();
    }
    if (!candidates.isEmpty()) {
      MethodNode closestMatch;
      if (scope.isMethodCall()) {
        closestMatch=findMethodDeclaration0(candidates,scope.getMethodCallArgumentTypes());
        confidence=TypeConfidence.INFERRED;
      }
 else {
        closestMatch=candidates.get(0);
        confidence=TypeConfidence.LOOSELY_INFERRED;
      }
      return new TypeLookupResult(closestMatch.getReturnType(),closestMatch.getDeclaringClass(),closestMatch,confidence,scope);
    }
  }
  if (!(node instanceof TupleExpression) && nodeType.equals(VariableScope.OBJECT_CLASS_NODE)) {
    confidence=TypeConfidence.UNKNOWN;
  }
  return new TypeLookupResult(nodeType,declaringType,null,confidence,scope);
}