Program: 190697
Project: 190697
Buggy source:
/** 
 * Generate the proper schema fragment for the given element property into the specified schema compositor. The element property may or may not represent a collection and it may or may not be wrapped.
 * @param ep the element property
 */
private Tree handleElementProp(final ElementPropertyInfo<T,C> ep){
  if (ep.isValueList()) {
    return new Tree.Term(){
      protected void write(      ContentModelContainer parent,      boolean isOptional,      boolean repeated){
        TypeRef<T,C> t=ep.getTypes().get(0);
        LocalElement e=parent.element();
        QName tn=t.getTagName();
        e.name(tn.getLocalPart());
        List lst=e.simpleType().list();
        writeTypeRef(lst,t,"String_Node_Str");
        elementFormDefault.writeForm(e,tn);
        writeOccurs(e,isOptional,repeated);
      }
    }
;
  }
  ArrayList<Tree> children=new ArrayList<Tree>();
  for (  final TypeRef<T,C> t : ep.getTypes()) {
    children.add(new Tree.Term(){
      protected void write(      ContentModelContainer parent,      boolean isOptional,      boolean repeated){
        LocalElement e=parent.element();
        QName tn=t.getTagName();
        if (canBeDirectElementRef(t,tn) || (!tn.getNamespaceURI().equals(uri) && tn.getNamespaceURI().length() > 0)) {
          e.ref(tn);
        }
 else {
          e.name(tn.getLocalPart());
          writeTypeRef(e,t,"String_Node_Str");
          elementFormDefault.writeForm(e,tn);
        }
        if (t.isNillable()) {
          e.nillable(true);
        }
        if (t.getDefaultValue() != null)         e._default(t.getDefaultValue());
        writeOccurs(e,isOptional,repeated);
      }
    }
);
  }
  final Tree choice=Tree.makeGroup(GroupKind.CHOICE,children).makeOptional(!ep.isRequired()).makeRepeated(ep.isCollection());
  final QName ename=ep.getXmlName();
  if (ename != null) {
    return new Tree.Term(){
      protected void write(      ContentModelContainer parent,      boolean isOptional,      boolean repeated){
        LocalElement e=parent.element();
        if (ename.getNamespaceURI().length() > 0) {
          if (!ename.getNamespaceURI().equals(uri)) {
            e.ref(new QName(ename.getNamespaceURI(),ename.getLocalPart()));
            return;
          }
        }
        e.name(ename.getLocalPart());
        elementFormDefault.writeForm(e,ename);
        if (ep.isCollectionNillable()) {
          e.nillable(true);
        }
        writeOccurs(e,true,repeated);
        ComplexType p=e.complexType();
        choice.write(p);
      }
    }
;
  }
 else {
    return choice;
  }
}

Fixed version (ground truth):
/** 
 * Generate the proper schema fragment for the given element property into the specified schema compositor. The element property may or may not represent a collection and it may or may not be wrapped.
 * @param ep the element property
 */
private Tree handleElementProp(final ElementPropertyInfo<T,C> ep){
  if (ep.isValueList()) {
    return new Tree.Term(){
      protected void write(      ContentModelContainer parent,      boolean isOptional,      boolean repeated){
        TypeRef<T,C> t=ep.getTypes().get(0);
        LocalElement e=parent.element();
        e.block();
        QName tn=t.getTagName();
        e.name(tn.getLocalPart());
        List lst=e.simpleType().list();
        writeTypeRef(lst,t,"String_Node_Str");
        elementFormDefault.writeForm(e,tn);
        writeOccurs(e,isOptional || !ep.isRequired(),repeated);
      }
    }
;
  }
  ArrayList<Tree> children=new ArrayList<Tree>();
  for (  final TypeRef<T,C> t : ep.getTypes()) {
    children.add(new Tree.Term(){
      protected void write(      ContentModelContainer parent,      boolean isOptional,      boolean repeated){
        LocalElement e=parent.element();
        QName tn=t.getTagName();
        if (canBeDirectElementRef(t,tn) || (!tn.getNamespaceURI().equals(uri) && tn.getNamespaceURI().length() > 0)) {
          e.ref(tn);
        }
 else {
          e.name(tn.getLocalPart());
          writeTypeRef(e,t,"String_Node_Str");
          elementFormDefault.writeForm(e,tn);
        }
        if (t.isNillable()) {
          e.nillable(true);
        }
        if (t.getDefaultValue() != null)         e._default(t.getDefaultValue());
        writeOccurs(e,isOptional,repeated);
      }
    }
);
  }
  final Tree choice=Tree.makeGroup(GroupKind.CHOICE,children).makeOptional(!ep.isRequired()).makeRepeated(ep.isCollection());
  final QName ename=ep.getXmlName();
  if (ename != null) {
    return new Tree.Term(){
      protected void write(      ContentModelContainer parent,      boolean isOptional,      boolean repeated){
        LocalElement e=parent.element();
        if (ename.getNamespaceURI().length() > 0) {
          if (!ename.getNamespaceURI().equals(uri)) {
            e.ref(new QName(ename.getNamespaceURI(),ename.getLocalPart()));
            return;
          }
        }
        e.name(ename.getLocalPart());
        elementFormDefault.writeForm(e,ename);
        if (ep.isCollectionNillable()) {
          e.nillable(true);
        }
        writeOccurs(e,true,repeated);
        ComplexType p=e.complexType();
        choice.write(p);
      }
    }
;
  }
 else {
    return choice;
  }
}