Program: 185415
Project: 185415
Buggy source:
protected ASTNode findDeclarationForDynamicVariable(VariableExpression var,ClassNode owner,VariableScope scope,int resolveStrategy){
  ASTNode candidate=null;
  List<ClassNode> callArgs=scope.getMethodCallArgumentTypes();
  boolean isLhsExpr=(scope.getWormhole().remove("String_Node_Str") == var);
  if (resolveStrategy == Closure.DELEGATE_FIRST || resolveStrategy == Closure.DELEGATE_ONLY) {
    candidate=findDeclaration(var.getName(),scope.getDelegate(),isLhsExpr,false,false,callArgs);
  }
  if (candidate == null && resolveStrategy < Closure.DELEGATE_ONLY) {
    VariableScope outer=(VariableScope)owner.getNodeMetaData("String_Node_Str");
    if (outer != null) {
      if (isLhsExpr)       scope.getWormhole().put("String_Node_Str",var);
      VariableScope.CallAndType cat=outer.getEnclosingMethodCallExpression();
      int enclosingResolveStrategy=(cat == null ? 0 : cat.getResolveStrategy(outer.getEnclosingClosure()));
      candidate=findDeclarationForDynamicVariable(var,outer.getOwner(),outer,enclosingResolveStrategy);
    }
 else {
      candidate=findDeclaration(var.getName(),owner,isLhsExpr,scope.isOwnerStatic(),scope.isFieldAccessDirect(),callArgs);
    }
    if (candidate == null && resolveStrategy < Closure.DELEGATE_FIRST && scope.getEnclosingClosure() != null) {
      candidate=findDeclaration(var.getName(),scope.getDelegate(),isLhsExpr,false,false,callArgs);
    }
  }
  if (candidate == null && (resolveStrategy <= Closure.DELEGATE_FIRST || resolveStrategy == Closure.TO_SELF) && (resolveStrategy > 0 || scope.getEnclosingClosure() != null)) {
    candidate=findDeclaration(var.getName(),VariableScope.CLOSURE_CLASS_NODE,isLhsExpr,false,false,callArgs);
  }
  return candidate;
}

Fixed version (ground truth):
protected ASTNode findDeclarationForDynamicVariable(VariableExpression var,ClassNode owner,VariableScope scope,int resolveStrategy){
  ASTNode candidate=null;
  List<ClassNode> callArgs=scope.getMethodCallArgumentTypes();
  boolean isLhsExpr=(scope.getWormhole().remove("String_Node_Str") == var);
  if (resolveStrategy == Closure.DELEGATE_FIRST || resolveStrategy == Closure.DELEGATE_ONLY) {
    candidate=findDeclaration(var.getName(),scope.getDelegate(),isLhsExpr,false,false,callArgs);
  }
  if (candidate == null && resolveStrategy < Closure.DELEGATE_ONLY) {
    VariableScope outer=(VariableScope)owner.getNodeMetaData("String_Node_Str");
    if (outer != null) {
      if (isLhsExpr)       scope.getWormhole().put("String_Node_Str",var);
      VariableScope.CallAndType cat=outer.getEnclosingMethodCallExpression();
      int enclosingResolveStrategy=(cat == null ? 0 : cat.getResolveStrategy(outer.getEnclosingClosure()));
      candidate=findDeclarationForDynamicVariable(var,getBaseDeclaringType(outer.getOwner()),outer,enclosingResolveStrategy);
    }
 else {
      candidate=findDeclaration(var.getName(),owner,isLhsExpr,scope.isOwnerStatic(),scope.isFieldAccessDirect(),callArgs);
    }
    if (candidate == null && resolveStrategy < Closure.DELEGATE_FIRST && scope.getEnclosingClosure() != null) {
      candidate=findDeclaration(var.getName(),scope.getDelegate(),isLhsExpr,false,false,callArgs);
    }
  }
  if (candidate == null && (resolveStrategy <= Closure.DELEGATE_FIRST || resolveStrategy == Closure.TO_SELF) && (resolveStrategy > 0 || scope.getEnclosingClosure() != null)) {
    candidate=findDeclaration(var.getName(),VariableScope.CLOSURE_CLASS_NODE,isLhsExpr,false,false,callArgs);
  }
  return candidate;
}