Program: 61635
Project: 61635
Buggy source:
public Trait[] generateTraitsPhase1(String className,String superName,boolean generateStatic,SourceGeneratorLocalData localData,List<GraphTargetItem> items,Traits ts) throws AVM2ParseException, CompilationException {
  Trait[] traits=new Trait[items.size()];
  int slot_id=1;
  int disp_id=3;
  for (int k=0; k < items.size(); k++) {
    GraphTargetItem item=items.get(k);
    if (item instanceof InterfaceAVM2Item) {
      TraitClass tc=new TraitClass();
      ClassInfo ci=new ClassInfo();
      InstanceInfo ii=new InstanceInfo();
      abc.class_info.add(ci);
      abc.instance_info.add(ii);
      ii.flags|=InstanceInfo.CLASS_INTERFACE;
      tc.class_info=abc.instance_info.size() - 1;
      tc.kindType=Trait.TRAIT_CLASS;
      tc.slot_id=0;
      ts.traits.add(tc);
      traits[k]=tc;
    }
    if (item instanceof ClassAVM2Item) {
      TraitClass tc=new TraitClass();
      ClassInfo ci=new ClassInfo();
      InstanceInfo instanceInfo=new InstanceInfo();
      abc.class_info.add(ci);
      abc.instance_info.add(instanceInfo);
      tc.class_info=abc.instance_info.size() - 1;
      tc.kindType=Trait.TRAIT_CLASS;
      tc.slot_id=slot_id++;
      ts.traits.add(tc);
      traits[k]=tc;
    }
    if ((item instanceof SlotAVM2Item) || (item instanceof ConstAVM2Item)) {
      TraitSlotConst tsc=new TraitSlotConst();
      tsc.kindType=(item instanceof SlotAVM2Item) ? Trait.TRAIT_SLOT : Trait.TRAIT_CONST;
      String var=null;
      GraphTargetItem val=null;
      GraphTargetItem type=null;
      boolean isNamespace=false;
      int namespace=0;
      boolean isStatic=false;
      if (item instanceof SlotAVM2Item) {
        SlotAVM2Item sai=(SlotAVM2Item)item;
        if (sai.isStatic() != generateStatic) {
          continue;
        }
        var=sai.var;
        val=sai.value;
        type=sai.type;
        isStatic=sai.isStatic();
        namespace=sai.getNamespace();
      }
      if (item instanceof ConstAVM2Item) {
        ConstAVM2Item cai=(ConstAVM2Item)item;
        if (cai.isStatic() != generateStatic) {
          continue;
        }
        var=cai.var;
        val=cai.value;
        type=cai.type;
        namespace=cai.getNamespace();
        isNamespace=type.toString().equals("String_Node_Str");
        isStatic=cai.isStatic();
      }
      if (isNamespace) {
        tsc.name_index=traitName(namespace,var);
      }
      tsc.type_index=isNamespace ? 0 : (type == null ? 0 : typeName(localData,type));
      ValueKind vk=getValueKind(namespace,type,val);
      if (vk == null) {
        tsc.value_kind=ValueKind.CONSTANT_Undefined;
      }
 else {
        tsc.value_kind=vk.value_kind;
        tsc.value_index=vk.value_index;
      }
      tsc.slot_id=isStatic ? slot_id++ : 0;
      ts.traits.add(tsc);
      traits[k]=tsc;
    }
    if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) {
      MethodAVM2Item mai=(MethodAVM2Item)item;
      if (mai.isStatic() != generateStatic) {
        continue;
      }
      TraitMethodGetterSetter tmgs=new TraitMethodGetterSetter();
      tmgs.kindType=(item instanceof GetterAVM2Item) ? Trait.TRAIT_GETTER : ((item instanceof SetterAVM2Item) ? Trait.TRAIT_SETTER : Trait.TRAIT_METHOD);
      tmgs.disp_id=mai.isStatic() ? disp_id++ : 0;
      if (mai.isFinal() || mai.isStatic()) {
        tmgs.kindFlags|=Trait.ATTR_Final;
      }
      if (mai.isOverride()) {
        tmgs.kindFlags|=Trait.ATTR_Override;
      }
      ts.traits.add(tmgs);
      traits[k]=tmgs;
    }
 else     if (item instanceof FunctionAVM2Item) {
      TraitFunction tf=new TraitFunction();
      tf.slot_id=slot_id++;
      tf.kindType=Trait.TRAIT_FUNCTION;
      ts.traits.add(tf);
      traits[k]=tf;
    }
  }
  return traits;
}

Fixed version (ground truth):
public Trait[] generateTraitsPhase1(String className,String superName,boolean generateStatic,SourceGeneratorLocalData localData,List<GraphTargetItem> items,Traits ts,Reference<Integer> classIndex) throws AVM2ParseException, CompilationException {
  Trait[] traits=new Trait[items.size()];
  int slot_id=1;
  int disp_id=3;
  for (int k=0; k < items.size(); k++) {
    GraphTargetItem item=items.get(k);
    if (item instanceof InterfaceAVM2Item) {
      TraitClass tc=new TraitClass();
      ClassInfo ci=new ClassInfo();
      InstanceInfo ii=new InstanceInfo();
      tc.class_info=classIndex.getVal();
      abc.addClass(ci,ii,classIndex.getVal());
      classIndex.setVal(classIndex.getVal() + 1);
      ii.flags|=InstanceInfo.CLASS_INTERFACE;
      tc.kindType=Trait.TRAIT_CLASS;
      tc.slot_id=0;
      ts.traits.add(tc);
      traits[k]=tc;
    }
    if (item instanceof ClassAVM2Item) {
      TraitClass tc=new TraitClass();
      ClassInfo ci=new ClassInfo();
      InstanceInfo ii=new InstanceInfo();
      tc.class_info=classIndex.getVal();
      abc.addClass(ci,ii,classIndex.getVal());
      classIndex.setVal(classIndex.getVal() + 1);
      tc.kindType=Trait.TRAIT_CLASS;
      tc.slot_id=slot_id++;
      ts.traits.add(tc);
      traits[k]=tc;
    }
    if ((item instanceof SlotAVM2Item) || (item instanceof ConstAVM2Item)) {
      TraitSlotConst tsc=new TraitSlotConst();
      tsc.kindType=(item instanceof SlotAVM2Item) ? Trait.TRAIT_SLOT : Trait.TRAIT_CONST;
      String var=null;
      GraphTargetItem val=null;
      GraphTargetItem type=null;
      boolean isNamespace=false;
      int namespace=0;
      boolean isStatic=false;
      if (item instanceof SlotAVM2Item) {
        SlotAVM2Item sai=(SlotAVM2Item)item;
        if (sai.isStatic() != generateStatic) {
          continue;
        }
        var=sai.var;
        val=sai.value;
        type=sai.type;
        isStatic=sai.isStatic();
        namespace=sai.getNamespace();
      }
      if (item instanceof ConstAVM2Item) {
        ConstAVM2Item cai=(ConstAVM2Item)item;
        if (cai.isStatic() != generateStatic) {
          continue;
        }
        var=cai.var;
        val=cai.value;
        type=cai.type;
        namespace=cai.getNamespace();
        isNamespace=type.toString().equals("String_Node_Str");
        isStatic=cai.isStatic();
      }
      if (isNamespace) {
        tsc.name_index=traitName(namespace,var);
      }
      tsc.type_index=isNamespace ? 0 : (type == null ? 0 : typeName(localData,type));
      ValueKind vk=getValueKind(namespace,type,val);
      if (vk == null) {
        tsc.value_kind=ValueKind.CONSTANT_Undefined;
      }
 else {
        tsc.value_kind=vk.value_kind;
        tsc.value_index=vk.value_index;
      }
      tsc.slot_id=isStatic ? slot_id++ : 0;
      ts.traits.add(tsc);
      traits[k]=tsc;
    }
    if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) {
      MethodAVM2Item mai=(MethodAVM2Item)item;
      if (mai.isStatic() != generateStatic) {
        continue;
      }
      TraitMethodGetterSetter tmgs=new TraitMethodGetterSetter();
      tmgs.kindType=(item instanceof GetterAVM2Item) ? Trait.TRAIT_GETTER : ((item instanceof SetterAVM2Item) ? Trait.TRAIT_SETTER : Trait.TRAIT_METHOD);
      tmgs.disp_id=mai.isStatic() ? disp_id++ : 0;
      if (mai.isFinal() || mai.isStatic()) {
        tmgs.kindFlags|=Trait.ATTR_Final;
      }
      if (mai.isOverride()) {
        tmgs.kindFlags|=Trait.ATTR_Override;
      }
      ts.traits.add(tmgs);
      traits[k]=tmgs;
    }
 else     if (item instanceof FunctionAVM2Item) {
      TraitFunction tf=new TraitFunction();
      tf.slot_id=slot_id++;
      tf.kindType=Trait.TRAIT_FUNCTION;
      ts.traits.add(tf);
      traits[k]=tf;
    }
  }
  return traits;
}