Program: 185591
Project: 185591
Buggy source:
@Override public void visitImports(ModuleNode node){
  for (  ImportNode imp : GroovyUtils.getAllImportNodes(node)) {
    IJavaElement oldEnclosingElement=enclosingElement;
    visitAnnotations(imp);
    ClassNode type=imp.getType();
    if (type != null) {
      String importName=imp.getClassName().replace('$','.') + (imp.getFieldName() != null ? "String_Node_Str" + imp.getFieldName() : "String_Node_Str");
      enclosingElement=unit.getImport(importName);
      if (!enclosingElement.exists()) {
        enclosingElement=oldEnclosingElement;
      }
    }
    try {
      TypeLookupResult result=null;
      VariableScope scope=scopes.getLast();
      scope.setPrimaryNode(false);
      assignmentStorer.storeImport(imp,scope);
      for (      ITypeLookup lookup : lookups) {
        TypeLookupResult candidate=lookup.lookupType(imp,scope);
        if (candidate != null) {
          if (result == null || result.confidence.isLessThan(candidate.confidence)) {
            result=candidate;
          }
          if (result.confidence.isAtLeast(TypeConfidence.INFERRED)) {
            break;
          }
        }
      }
      VisitStatus status=notifyRequestor(imp,requestor,result);
switch (status) {
case CONTINUE:
        try {
          if (type != null) {
            visitClassReference(type);
            completeExpressionStack.add(imp);
            if (imp.getFieldNameExpr() != null) {
              primaryTypeStack.add(type);
              imp.getFieldNameExpr().visit(this);
              dependentDeclarationStack.removeLast();
              dependentTypeStack.removeLast();
            }
            completeExpressionStack.removeLast();
          }
        }
 catch (        VisitCompleted e) {
          if (e.status == VisitStatus.STOP_VISIT) {
            throw e;
          }
        }
case CANCEL_MEMBER:
      continue;
case CANCEL_BRANCH:
    return;
case STOP_VISIT:
  throw new VisitCompleted(status);
}
}
  finally {
enclosingElement=oldEnclosingElement;
}
}
}

Fixed version (ground truth):
@Override public void visitImports(ModuleNode node){
  for (  ImportNode imp : GroovyUtils.getAllImportNodes(node)) {
    IJavaElement oldEnclosingElement=enclosingElement;
    visitAnnotations(imp);
    String importName;
    if (imp.isStar()) {
      if (!imp.isStatic()) {
        importName=imp.getPackageName() + "String_Node_Str";
      }
 else {
        importName=imp.getClassName().replace('$','.') + "String_Node_Str";
      }
    }
 else {
      if (!imp.isStatic()) {
        importName=imp.getClassName().replace('$','.');
      }
 else {
        importName=imp.getClassName().replace('$','.') + "String_Node_Str" + imp.getFieldName();
      }
    }
    enclosingElement=unit.getImport(importName);
    if (!enclosingElement.exists()) {
      enclosingElement=oldEnclosingElement;
    }
    try {
      TypeLookupResult result=null;
      VariableScope scope=scopes.getLast();
      scope.setPrimaryNode(false);
      assignmentStorer.storeImport(imp,scope);
      for (      ITypeLookup lookup : lookups) {
        TypeLookupResult candidate=lookup.lookupType(imp,scope);
        if (candidate != null) {
          if (result == null || result.confidence.isLessThan(candidate.confidence)) {
            result=candidate;
          }
          if (result.confidence.isAtLeast(TypeConfidence.INFERRED)) {
            break;
          }
        }
      }
      VisitStatus status=notifyRequestor(imp,requestor,result);
switch (status) {
case CONTINUE:
        try {
          ClassNode type=imp.getType();
          if (type != null) {
            visitClassReference(type);
            completeExpressionStack.add(imp);
            if (imp.getFieldNameExpr() != null) {
              primaryTypeStack.add(type);
              imp.getFieldNameExpr().visit(this);
              dependentDeclarationStack.removeLast();
              dependentTypeStack.removeLast();
            }
            completeExpressionStack.removeLast();
          }
        }
 catch (        VisitCompleted e) {
          if (e.status == VisitStatus.STOP_VISIT) {
            throw e;
          }
        }
case CANCEL_MEMBER:
      continue;
case CANCEL_BRANCH:
    return;
case STOP_VISIT:
  throw new VisitCompleted(status);
}
}
  finally {
enclosingElement=oldEnclosingElement;
}
}
}