Program: 61494
Project: 61494
Buggy source:
public static int resolveType(SourceGeneratorLocalData localData,GraphTargetItem item,AbcIndexing abc) throws CompilationException {
  int name_index=0;
  GraphTargetItem typeItem=null;
  if (item instanceof UnresolvedAVM2Item) {
    String fullClass=localData.getFullClass();
    item=((UnresolvedAVM2Item)item).resolve(new TypeItem(fullClass),new ArrayList<>(),new ArrayList<>(),abc,new ArrayList<>(),new ArrayList<>());
  }
  if (item instanceof TypeItem) {
    typeItem=item;
  }
 else   if (item instanceof ApplyTypeAVM2Item) {
    typeItem=((ApplyTypeAVM2Item)item).object;
  }
 else {
    throw new CompilationException("String_Node_Str" + item + "String_Node_Str"+ item.getClass().getName()+ "String_Node_Str",0);
  }
  if (typeItem instanceof UnresolvedAVM2Item) {
    String fullClass=localData.getFullClass();
    typeItem=((UnresolvedAVM2Item)typeItem).resolve(new TypeItem(fullClass),new ArrayList<>(),new ArrayList<>(),abc,new ArrayList<>(),new ArrayList<>());
  }
  if (!(typeItem instanceof TypeItem)) {
    throw new CompilationException("String_Node_Str",0);
  }
  TypeItem type=(TypeItem)typeItem;
  DottedChain dname=type.fullTypeName;
  String pkg=dname.getWithoutLast().toRawString();
  String name=dname.getLast();
  AbcIndexing.ClassIndex ci=abc.findClass(new TypeItem(dname));
  if (ci != null) {
    Multiname m=ci.abc.instance_info.get(ci.index).getName(ci.abc.constants);
    if (m != null) {
      Namespace ns=ci.abc.instance_info.get(ci.index).getName(ci.abc.constants).getNamespace(ci.abc.constants);
      String n=m.getName(ci.abc.constants,new ArrayList<DottedChain>(),true);
      String nsn=ns == null ? null : ns.getName(ci.abc.constants).toRawString();
      name_index=abc.getSelectedAbc().constants.getQnameId(n,ns == null ? Namespace.KIND_PACKAGE : ns.kind,nsn,true);
    }
  }
  for (int i=1; i < abc.getSelectedAbc().constants.getMultinameCount(); i++) {
    Multiname mname=abc.getSelectedAbc().constants.getMultiname(i);
    if (mname != null && name.equals(mname.getName(abc.getSelectedAbc().constants,null,true))) {
      if (mname.getNamespace(abc.getSelectedAbc().constants) != null && pkg.equals(mname.getNamespace(abc.getSelectedAbc().constants).getName(abc.getSelectedAbc().constants))) {
        name_index=i;
        break;
      }
    }
  }
  if (name_index == 0) {
    if (pkg.isEmpty() && localData.currentScript != null) {
      for (      Trait t : localData.currentScript.traits.traits) {
        if (t.getName(abc.getSelectedAbc()).getName(abc.getSelectedAbc().constants,null,true).equals(name)) {
          name_index=t.name_index;
          break;
        }
      }
    }
    if (name_index == 0) {
      name_index=abc.getSelectedAbc().constants.getMultinameId(new Multiname(Multiname.QNAME,abc.getSelectedAbc().constants.getStringId(name,true),abc.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE,pkg,0,true),0),true);
    }
  }
  if (item instanceof ApplyTypeAVM2Item) {
    ApplyTypeAVM2Item atype=(ApplyTypeAVM2Item)item;
    int[] params=new int[atype.params.size()];
    int i=0;
    for (    GraphTargetItem s : atype.params) {
      params[i++]=resolveType(localData,s,abc);
    }
    return abc.getSelectedAbc().constants.getMultinameId(new Multiname(Multiname.TYPENAME,0,0,0,name_index,params),true);
  }
  return name_index;
}

Fixed version (ground truth):
public static int resolveType(SourceGeneratorLocalData localData,GraphTargetItem item,AbcIndexing abc) throws CompilationException {
  int name_index=0;
  GraphTargetItem typeItem=null;
  if (item instanceof UnresolvedAVM2Item) {
    String fullClass=localData.getFullClass();
    item=((UnresolvedAVM2Item)item).resolve(new TypeItem(fullClass),new ArrayList<>(),new ArrayList<>(),abc,new ArrayList<>(),new ArrayList<>());
  }
  if (item instanceof TypeItem) {
    typeItem=item;
  }
 else   if (item instanceof ApplyTypeAVM2Item) {
    typeItem=((ApplyTypeAVM2Item)item).object;
  }
 else {
    throw new CompilationException("String_Node_Str" + item + "String_Node_Str"+ item.getClass().getName()+ "String_Node_Str",0);
  }
  if (typeItem instanceof UnresolvedAVM2Item) {
    String fullClass=localData.getFullClass();
    typeItem=((UnresolvedAVM2Item)typeItem).resolve(new TypeItem(fullClass),new ArrayList<>(),new ArrayList<>(),abc,new ArrayList<>(),new ArrayList<>());
  }
  if (!(typeItem instanceof TypeItem)) {
    throw new CompilationException("String_Node_Str",0);
  }
  TypeItem type=(TypeItem)typeItem;
  DottedChain dname=type.fullTypeName;
  DottedChain pkg=dname.getWithoutLast();
  String name=dname.getLast();
  AbcIndexing.ClassIndex ci=abc.findClass(new TypeItem(dname));
  if (ci != null) {
    Multiname m=ci.abc.instance_info.get(ci.index).getName(ci.abc.constants);
    if (m != null) {
      Namespace ns=ci.abc.instance_info.get(ci.index).getName(ci.abc.constants).getNamespace(ci.abc.constants);
      String n=m.getName(ci.abc.constants,new ArrayList<>(),true);
      String nsn=ns == null ? null : ns.getName(ci.abc.constants).toRawString();
      name_index=abc.getSelectedAbc().constants.getQnameId(n,ns == null ? Namespace.KIND_PACKAGE : ns.kind,nsn,true);
    }
  }
  for (int i=1; i < abc.getSelectedAbc().constants.getMultinameCount(); i++) {
    Multiname mname=abc.getSelectedAbc().constants.getMultiname(i);
    if (mname != null && name.equals(mname.getName(abc.getSelectedAbc().constants,null,true))) {
      if (mname.getNamespace(abc.getSelectedAbc().constants) != null && pkg.equals(mname.getNamespace(abc.getSelectedAbc().constants).getName(abc.getSelectedAbc().constants))) {
        name_index=i;
        break;
      }
    }
  }
  if (name_index == 0) {
    if (pkg.isEmpty() && localData.currentScript != null) {
      for (      Trait t : localData.currentScript.traits.traits) {
        if (t.getName(abc.getSelectedAbc()).getName(abc.getSelectedAbc().constants,null,true).equals(name)) {
          name_index=t.name_index;
          break;
        }
      }
    }
    if (name_index == 0) {
      name_index=abc.getSelectedAbc().constants.getMultinameId(new Multiname(Multiname.QNAME,abc.getSelectedAbc().constants.getStringId(name,true),abc.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE,pkg,0,true),0),true);
    }
  }
  if (item instanceof ApplyTypeAVM2Item) {
    ApplyTypeAVM2Item atype=(ApplyTypeAVM2Item)item;
    int[] params=new int[atype.params.size()];
    int i=0;
    for (    GraphTargetItem s : atype.params) {
      params[i++]=resolveType(localData,s,abc);
    }
    return abc.getSelectedAbc().constants.getMultinameId(new Multiname(Multiname.TYPENAME,0,0,0,name_index,params),true);
  }
  return name_index;
}