Program: 185447
Project: 185447
Buggy source:
protected void importDef(AST importNode){
  try {
    output.putNodeMetaData(ImportNode.class,ImportNode.class);
    boolean isStatic=importNode.getType() == STATIC_IMPORT;
    List<AnnotationNode> annotations=new ArrayList<AnnotationNode>();
    AST node=importNode.getFirstChild();
    if (isType(ANNOTATIONS,node)) {
      processAnnotations(annotations,node);
      node=node.getNextSibling();
    }
    String alias=null;
    AST aliasNode=null;
    if (isType(LITERAL_as,node)) {
      node=node.getFirstChild();
      aliasNode=node.getNextSibling();
      alias=identifier(aliasNode);
    }
    if (node == null) {
      if (isStatic) {
        addStaticImport(ClassHelper.OBJECT_TYPE,"String_Node_Str",null,annotations);
      }
 else {
        addImport(ClassHelper.OBJECT_TYPE,"String_Node_Str",null,annotations);
      }
      return;
    }
    if (node.getNumberOfChildren() == 0) {
      String name=identifier(node);
      ClassNode type=ClassHelper.make(name);
      configureAST(type,importNode);
      addImport(type,name,alias,annotations);
      return;
    }
    AST packageNode=node.getFirstChild();
    String packageName=qualifiedName(packageNode);
    AST nameNode=packageNode.getNextSibling();
    if (isType(STAR,nameNode)) {
      if (isStatic) {
        ClassNode type=ClassHelper.make(packageName);
        configureAST(type,packageNode);
        addStaticStarImport(type,packageName,annotations);
        ASTNode imp=output.getStaticStarImports().get(packageName);
        if (type instanceof ImmutableClassNode) {
          ClassExpression typeNode=new ClassExpression(type);
          imp.setNodeMetaData(ClassExpression.class,typeNode);
          configureAST(typeNode,packageNode);
        }
        configureAST(imp,importNode);
      }
 else {
        addStarImport(packageName,annotations);
        ASTNode imp=output.getStarImports().get(output.getStarImports().size() - 1);
        configureAST(imp,importNode);
      }
      if (alias != null)       throw new GroovyBugError("String_Node_Str" + "String_Node_Str");
    }
 else {
      ImportNode imp;
      String name=identifier(nameNode);
      if (isStatic) {
        ClassNode type=ClassHelper.make(packageName);
        configureAST(type,packageNode);
        addStaticImport(type,name,alias,annotations);
        imp=output.getStaticImports().get(alias == null ? name : alias);
        if (type instanceof ImmutableClassNode) {
          ClassExpression typeNode=new ClassExpression(type);
          imp.setNodeMetaData(ClassExpression.class,typeNode);
          configureAST(typeNode,packageNode);
        }
        configureAST(imp,importNode);
        ConstantExpression nameExpr=new ConstantExpression(name);
        configureAST(nameExpr,nameNode);
        imp.setFieldNameExpr(nameExpr);
      }
 else {
        ClassNode type=ClassHelper.make(packageName + "String_Node_Str" + name);
        configureAST(type,nameNode);
        addImport(type,name,alias,annotations);
        imp=output.getImport(alias == null ? name : alias);
        if (type instanceof ImmutableClassNode) {
          ClassExpression typeNode=new ClassExpression(type);
          imp.setNodeMetaData(ClassExpression.class,typeNode);
          configureAST(typeNode,nameNode);
        }
        configureAST(imp,importNode);
      }
      if (alias != null) {
        ConstantExpression aliasExpr=new ConstantExpression(alias);
        configureAST(aliasExpr,aliasNode);
        imp.setAliasExpr(aliasExpr);
      }
    }
  }
  finally {
    Object node=output.getNodeMetaData(ImportNode.class);
    if (node != null && node != ImportNode.class) {
      configureAST((ImportNode)node,importNode);
    }
    output.removeNodeMetaData(ImportNode.class);
  }
}

Fixed version (ground truth):
protected void importDef(AST importNode){
  try {
    output.putNodeMetaData(ImportNode.class,ImportNode.class);
    boolean isStatic=importNode.getType() == STATIC_IMPORT;
    List<AnnotationNode> annotations=new ArrayList<AnnotationNode>();
    AST node=importNode.getFirstChild();
    if (isType(ANNOTATIONS,node)) {
      processAnnotations(annotations,node);
      node=node.getNextSibling();
    }
    String alias=null;
    AST aliasNode=null;
    if (isType(LITERAL_as,node)) {
      node=node.getFirstChild();
      aliasNode=node.getNextSibling();
      alias=identifier(aliasNode);
    }
    if (node.getNumberOfChildren() == 0) {
      String name=identifier(node);
      ClassNode type=ClassHelper.make(name);
      configureAST(type,importNode);
      addImport(type,name,alias,annotations);
      return;
    }
    AST packageNode=node.getFirstChild();
    String packageName=qualifiedName(packageNode);
    AST nameNode=packageNode.getNextSibling();
    if (isType(STAR,nameNode)) {
      if (isStatic) {
        ClassNode type=ClassHelper.make(packageName);
        configureAST(type,packageNode);
        addStaticStarImport(type,packageName,annotations);
        ASTNode imp=output.getStaticStarImports().get(packageName);
        if (type instanceof ImmutableClassNode) {
          ClassExpression typeNode=new ClassExpression(type);
          imp.setNodeMetaData(ClassExpression.class,typeNode);
          configureAST(typeNode,packageNode);
        }
        configureAST(imp,importNode);
      }
 else {
        addStarImport(packageName,annotations);
        ASTNode imp=output.getStarImports().get(output.getStarImports().size() - 1);
        configureAST(imp,importNode);
      }
      if (alias != null)       throw new GroovyBugError("String_Node_Str" + "String_Node_Str");
    }
 else {
      ImportNode imp;
      String name=identifier(nameNode);
      if (isStatic) {
        ClassNode type=ClassHelper.make(packageName);
        configureAST(type,packageNode);
        addStaticImport(type,name,alias,annotations);
        imp=output.getStaticImports().get(alias == null ? name : alias);
        if (type instanceof ImmutableClassNode) {
          ClassExpression typeNode=new ClassExpression(type);
          imp.setNodeMetaData(ClassExpression.class,typeNode);
          configureAST(typeNode,packageNode);
        }
        configureAST(imp,importNode);
        ConstantExpression nameExpr=new ConstantExpression(name);
        configureAST(nameExpr,nameNode);
        imp.setFieldNameExpr(nameExpr);
      }
 else {
        ClassNode type=ClassHelper.make(packageName + "String_Node_Str" + name);
        configureAST(type,nameNode);
        addImport(type,name,alias,annotations);
        imp=output.getImport(alias == null ? name : alias);
        if (type instanceof ImmutableClassNode) {
          ClassExpression typeNode=new ClassExpression(type);
          imp.setNodeMetaData(ClassExpression.class,typeNode);
          configureAST(typeNode,nameNode);
        }
        configureAST(imp,importNode);
      }
      if (alias != null) {
        ConstantExpression aliasExpr=new ConstantExpression(alias);
        configureAST(aliasExpr,aliasNode);
        imp.setAliasExpr(aliasExpr);
      }
    }
  }
  finally {
    Object node=output.getNodeMetaData(ImportNode.class);
    if (node != null && node != ImportNode.class) {
      configureAST((ImportNode)node,importNode);
    }
    output.removeNodeMetaData(ImportNode.class);
  }
}