Program: 101957
Project: 101957
Buggy source:
private String getContraints(BaseTable table){
  StringBuffer sb=new StringBuffer();
  boolean hasPK=table.getPrimaryKey() != null;
  boolean hasFKs=table.getForeignKeys().size() > 0;
  boolean hasAPs=table.getAccessPatterns().size() > 0;
  int nColumns=0;
  int count=0;
  Collection<UniqueConstraint> uniqueConstraints=getUniqueUniqueContraints(table);
  boolean hasUCs=uniqueConstraints.size() > 0;
  if (hasPK) {
    PrimaryKey pk=table.getPrimaryKey();
    String pkName=getName(pk);
    sb.append(COMMA);
    StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ pkName+ SPACE+ PRIMARY_KEY);
    nColumns=pk.getColumns().size();
    count=0;
    for (    Object col : pk.getColumns()) {
      count++;
      if (count == 1)       theSB.append(OPEN_BRACKET);
      theSB.append(getName((EObject)col));
      if (count < nColumns)       theSB.append(COMMA + SPACE);
 else       theSB.append(CLOSE_BRACKET);
    }
    String options=getOptions(pk);
    if (!StringUtilities.isEmpty(options)) {
      theSB.append(SPACE).append(options);
    }
    sb.append(theSB.toString());
    if ((hasFKs && includeFKs) || hasUCs || hasAPs)     sb.append(COMMA);
  }
  if (hasFKs && includeFKs) {
    int nFKs=table.getForeignKeys().size();
    int countFK=0;
    for (    Object obj : table.getForeignKeys()) {
      countFK++;
      ForeignKey fk=(ForeignKey)obj;
      String fkName=getName(fk);
      StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ fkName+ SPACE+ FOREIGN_KEY);
      nColumns=fk.getColumns().size();
      count=0;
      for (      Object col : fk.getColumns()) {
        count++;
        if (count == 1)         theSB.append(OPEN_BRACKET);
        theSB.append(getName((EObject)col));
        if (count < nColumns)         theSB.append(COMMA + SPACE);
 else         theSB.append(CLOSE_BRACKET);
      }
      if (fk.getTable() != null) {
        UniqueKey uk=fk.getUniqueKey();
        BaseTable fkTableRef=(BaseTable)uk.getTable();
        String fkTableRefName=getName(fkTableRef);
        theSB.append(SPACE).append(REFERENCES).append(SPACE).append(fkTableRefName);
        if (uk instanceof UniqueConstraint) {
          UniqueConstraint ucRef=fkTableRef.getUniqueConstraints().get(0);
          nColumns=ucRef.getColumns().size();
          count=0;
          for (          Object col : ucRef.getColumns()) {
            count++;
            if (count == 1)             theSB.append(OPEN_BRACKET);
            theSB.append(getName((EObject)col));
            if (count < nColumns)             theSB.append(COMMA + SPACE);
 else             theSB.append(CLOSE_BRACKET);
          }
        }
 else {
          PrimaryKey pkRef=fkTableRef.getPrimaryKey();
          nColumns=pkRef.getColumns().size();
          count=0;
          for (          Object col : pkRef.getColumns()) {
            count++;
            if (count == 1)             theSB.append(OPEN_BRACKET);
            theSB.append(getName((EObject)col));
            if (count < nColumns)             theSB.append(COMMA + SPACE);
 else             theSB.append(CLOSE_BRACKET);
          }
        }
      }
      String options=getOptions(fk);
      if (!StringUtilities.isEmpty(options)) {
        theSB.append(SPACE).append(options);
      }
      sb.append(theSB.toString());
      if (countFK < nFKs)       sb.append(COMMA);
    }
    if (hasUCs || hasAPs)     sb.append(COMMA);
  }
  if (hasUCs) {
    int nUCs=uniqueConstraints.size();
    int ucCount=0;
    for (    Object obj : uniqueConstraints) {
      ucCount++;
      UniqueConstraint uc=(UniqueConstraint)obj;
      String name=getName(uc);
      StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ name+ SPACE+ UNIQUE);
      nColumns=uc.getColumns().size();
      count=0;
      for (      Object col : uc.getColumns()) {
        count++;
        if (count == 1)         theSB.append(OPEN_BRACKET);
        theSB.append(getName((EObject)col));
        if (count < nColumns)         theSB.append(COMMA + SPACE);
 else         theSB.append(CLOSE_BRACKET);
      }
      String options=getOptions(uc);
      if (!StringUtilities.isEmpty(options)) {
        theSB.append(SPACE).append(options);
      }
      if (ucCount < nUCs)       sb.append(COMMA);
      sb.append(theSB.toString());
    }
  }
  if (!hasPK && !(hasFKs) && !hasUCs&& hasAPs) {
    sb.append(COMMA);
  }
  if (hasAPs) {
    int nAPs=table.getAccessPatterns().size();
    int apCount=0;
    for (    Object obj : table.getAccessPatterns()) {
      apCount++;
      AccessPattern ap=(AccessPattern)obj;
      String name=getName(ap);
      StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ name+ SPACE+ ACCESSPATTERN);
      nColumns=ap.getColumns().size();
      count=0;
      for (      Object col : ap.getColumns()) {
        count++;
        if (count == 1)         theSB.append(OPEN_BRACKET);
        theSB.append(getName((EObject)col));
        if (count < nColumns)         theSB.append(COMMA + SPACE);
 else         theSB.append(CLOSE_BRACKET);
      }
      if (apCount < nAPs)       sb.append(COMMA);
      sb.append(theSB.toString());
    }
  }
  return sb.toString();
}

Fixed version (ground truth):
private String getContraints(BaseTable table){
  StringBuffer sb=new StringBuffer();
  boolean hasPK=table.getPrimaryKey() != null;
  boolean hasFKs=table.getForeignKeys().size() > 0;
  boolean hasAPs=table.getAccessPatterns().size() > 0;
  int nColumns=0;
  int count=0;
  Collection<UniqueConstraint> uniqueConstraints=getUniqueUniqueContraints(table);
  boolean hasUCs=uniqueConstraints.size() > 0;
  if (hasPK) {
    PrimaryKey pk=table.getPrimaryKey();
    String pkName=getName(pk);
    StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ pkName+ SPACE+ PRIMARY_KEY);
    nColumns=pk.getColumns().size();
    count=0;
    for (    Object col : pk.getColumns()) {
      count++;
      if (count == 1)       theSB.append(OPEN_BRACKET);
      theSB.append(getName((EObject)col));
      if (count < nColumns)       theSB.append(COMMA + SPACE);
 else       theSB.append(CLOSE_BRACKET);
    }
    String options=getOptions(pk);
    if (!StringUtilities.isEmpty(options)) {
      theSB.append(SPACE).append(options);
    }
    sb.append(theSB.toString());
    if ((hasFKs && includeFKs) || hasUCs || hasAPs)     sb.append(COMMA);
  }
  if (hasFKs && includeFKs) {
    int nFKs=table.getForeignKeys().size();
    int countFK=0;
    for (    Object obj : table.getForeignKeys()) {
      countFK++;
      ForeignKey fk=(ForeignKey)obj;
      String fkName=getName(fk);
      StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ fkName+ SPACE+ FOREIGN_KEY);
      nColumns=fk.getColumns().size();
      count=0;
      for (      Object col : fk.getColumns()) {
        count++;
        if (count == 1)         theSB.append(OPEN_BRACKET);
        theSB.append(getName((EObject)col));
        if (count < nColumns)         theSB.append(COMMA + SPACE);
 else         theSB.append(CLOSE_BRACKET);
      }
      if (fk.getTable() != null) {
        UniqueKey uk=fk.getUniqueKey();
        BaseTable fkTableRef=(BaseTable)uk.getTable();
        String fkTableRefName=getName(fkTableRef);
        theSB.append(SPACE).append(REFERENCES).append(SPACE).append(fkTableRefName);
        if (uk instanceof UniqueConstraint) {
          UniqueConstraint ucRef=fkTableRef.getUniqueConstraints().get(0);
          nColumns=ucRef.getColumns().size();
          count=0;
          for (          Object col : ucRef.getColumns()) {
            count++;
            if (count == 1)             theSB.append(OPEN_BRACKET);
            theSB.append(getName((EObject)col));
            if (count < nColumns)             theSB.append(COMMA + SPACE);
 else             theSB.append(CLOSE_BRACKET);
          }
        }
 else {
          PrimaryKey pkRef=fkTableRef.getPrimaryKey();
          nColumns=pkRef.getColumns().size();
          count=0;
          for (          Object col : pkRef.getColumns()) {
            count++;
            if (count == 1)             theSB.append(OPEN_BRACKET);
            theSB.append(getName((EObject)col));
            if (count < nColumns)             theSB.append(COMMA + SPACE);
 else             theSB.append(CLOSE_BRACKET);
          }
        }
      }
      String options=getOptions(fk);
      if (!StringUtilities.isEmpty(options)) {
        theSB.append(SPACE).append(options);
      }
      sb.append(theSB.toString());
      if (countFK < nFKs)       sb.append(COMMA);
    }
    if (hasUCs || hasAPs)     sb.append(COMMA);
  }
  if (hasUCs) {
    int nUCs=uniqueConstraints.size();
    int ucCount=0;
    for (    Object obj : uniqueConstraints) {
      ucCount++;
      UniqueConstraint uc=(UniqueConstraint)obj;
      String name=getName(uc);
      StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ name+ SPACE+ UNIQUE);
      nColumns=uc.getColumns().size();
      count=0;
      for (      Object col : uc.getColumns()) {
        count++;
        if (count == 1)         theSB.append(OPEN_BRACKET);
        theSB.append(getName((EObject)col));
        if (count < nColumns)         theSB.append(COMMA + SPACE);
 else         theSB.append(CLOSE_BRACKET);
      }
      String options=getOptions(uc);
      if (!StringUtilities.isEmpty(options)) {
        theSB.append(SPACE).append(options);
      }
      if (ucCount < nUCs)       sb.append(COMMA);
      sb.append(theSB.toString());
    }
  }
  if (!hasPK && !(hasFKs) && !hasUCs&& hasAPs) {
    sb.append(COMMA);
  }
  if (hasAPs) {
    int nAPs=table.getAccessPatterns().size();
    int apCount=0;
    for (    Object obj : table.getAccessPatterns()) {
      apCount++;
      AccessPattern ap=(AccessPattern)obj;
      String name=getName(ap);
      StringBuilder theSB=new StringBuilder(NEW_LINE + TAB + CONSTRAINT+ SPACE+ name+ SPACE+ ACCESSPATTERN);
      nColumns=ap.getColumns().size();
      count=0;
      for (      Object col : ap.getColumns()) {
        count++;
        if (count == 1)         theSB.append(OPEN_BRACKET);
        theSB.append(getName((EObject)col));
        if (count < nColumns)         theSB.append(COMMA + SPACE);
 else         theSB.append(CLOSE_BRACKET);
      }
      if (apCount < nAPs)       sb.append(COMMA);
      sb.append(theSB.toString());
    }
  }
  return sb.toString();
}