Program: 91826
Project: 91826
Buggy source:
/** 
 * Builds the feature type from the information and properties specified to this builder. One of the   {@code setName(…)} methods must have been invoked before this {@code build()} method (mandatory).All other methods are optional, but some calls to a  {@code add} method are usually needed.
 * @return the new feature type.
 * @throws IllegalStateException if the feature type contains incompatible{@linkplain AttributeTypeBuilder#setCRS CRS characteristics}.
 */
public FeatureType build() throws IllegalStateException {
  if (feature == null) {
    final int numSpecified=properties.size();
    int numSynthetic;
    int envelopeIndex=-1;
    int geometryIndex=-1;
    final PropertyType[] identifierTypes;
    if (identifierCount == 0) {
      numSynthetic=0;
      identifierTypes=null;
    }
 else {
      numSynthetic=1;
      identifierTypes=new PropertyType[identifierCount];
    }
    if (defaultGeometry != null) {
      envelopeIndex=numSynthetic++;
      if (!AttributeConvention.GEOMETRY_PROPERTY.equals(defaultGeometry.getName())) {
        geometryIndex=numSynthetic++;
      }
    }
    final PropertyType[] propertyTypes=new PropertyType[numSynthetic + numSpecified];
    int propertyCursor=numSynthetic;
    int identifierCursor=0;
    for (int i=0; i < numSpecified; i++) {
      final PropertyTypeBuilder builder=properties.get(i);
      final PropertyType instance=builder.build();
      propertyTypes[propertyCursor]=instance;
      if (builder.isIdentifier()) {
        identifierTypes[identifierCursor++]=instance;
      }
      if (builder == defaultGeometry && geometryIndex >= 0) {
        if (propertyTypes[geometryIndex] != null) {
          throw new CorruptedObjectException();
        }
        propertyTypes[geometryIndex]=FeatureOperations.link(name(AttributeConvention.GEOMETRY_PROPERTY),instance);
      }
      propertyCursor++;
    }
    if (envelopeIndex >= 0)     try {
      propertyTypes[envelopeIndex]=FeatureOperations.envelope(name(AttributeConvention.ENVELOPE_PROPERTY),null,propertyTypes);
    }
 catch (    FactoryException e) {
      throw new IllegalStateException(e);
    }
    if (identifierTypes != null) {
      if (identifierCursor != identifierTypes.length) {
        throw new CorruptedObjectException();
      }
      if (AttributeConvention.IDENTIFIER_PROPERTY.equals(identifierTypes[0].getName())) {
        if (identifierCursor > 1) {
          throw new IllegalStateException(Errors.format(Errors.Keys.PropertyAlreadyExists_2,getDisplayName(),AttributeConvention.IDENTIFIER_PROPERTY));
        }
        System.arraycopy(propertyTypes,1,propertyTypes,0,--propertyCursor);
      }
 else {
        propertyTypes[0]=FeatureOperations.compound(name(AttributeConvention.IDENTIFIER_PROPERTY),idDelimiter,idPrefix,idSuffix,identifierTypes);
      }
    }
    feature=new DefaultFeatureType(identification(),isAbstract(),superTypes.toArray(new FeatureType[superTypes.size()]),ArraysExt.resize(propertyTypes,propertyCursor));
  }
  return feature;
}

Fixed version (ground truth):
/** 
 * Builds the feature type from the information and properties specified to this builder. One of the   {@code setName(…)} methods must have been invoked before this {@code build()} method (mandatory).All other methods are optional, but some calls to a  {@code add} method are usually needed.<p>If a feature type has already been built and this builder state has not changed since the feature type creation, then the previously created  {@code FeatureType} instance is returned.</p>
 * @return the feature type.
 * @throws IllegalStateException if the builder contains inconsistent information.
 */
@Override public FeatureType build() throws IllegalStateException {
  if (feature == null) {
    final int numSpecified=properties.size();
    int numSynthetic;
    int envelopeIndex=-1;
    int geometryIndex=-1;
    final PropertyType[] identifierTypes;
    if (identifierCount == 0) {
      numSynthetic=0;
      identifierTypes=null;
    }
 else {
      numSynthetic=1;
      identifierTypes=new PropertyType[identifierCount];
    }
    if (defaultGeometry != null) {
      envelopeIndex=numSynthetic++;
      if (!AttributeConvention.GEOMETRY_PROPERTY.equals(defaultGeometry.getName())) {
        geometryIndex=numSynthetic++;
      }
    }
    final PropertyType[] propertyTypes=new PropertyType[numSynthetic + numSpecified];
    int propertyCursor=numSynthetic;
    int identifierCursor=0;
    for (int i=0; i < numSpecified; i++) {
      final PropertyTypeBuilder builder=properties.get(i);
      final PropertyType instance=builder.build();
      propertyTypes[propertyCursor]=instance;
      if (builder.isIdentifier()) {
        identifierTypes[identifierCursor++]=instance;
      }
      if (builder == defaultGeometry && geometryIndex >= 0) {
        if (propertyTypes[geometryIndex] != null) {
          throw new CorruptedObjectException();
        }
        propertyTypes[geometryIndex]=FeatureOperations.link(name(AttributeConvention.GEOMETRY_PROPERTY),instance);
      }
      propertyCursor++;
    }
    if (envelopeIndex >= 0)     try {
      propertyTypes[envelopeIndex]=FeatureOperations.envelope(name(AttributeConvention.ENVELOPE_PROPERTY),null,propertyTypes);
    }
 catch (    FactoryException e) {
      throw new IllegalStateException(e);
    }
    if (identifierTypes != null) {
      if (identifierCursor != identifierTypes.length) {
        throw new CorruptedObjectException();
      }
      if (AttributeConvention.IDENTIFIER_PROPERTY.equals(identifierTypes[0].getName())) {
        if (identifierCursor > 1) {
          throw new IllegalStateException(Errors.format(Errors.Keys.PropertyAlreadyExists_2,getDisplayName(),AttributeConvention.IDENTIFIER_PROPERTY));
        }
        System.arraycopy(propertyTypes,1,propertyTypes,0,--propertyCursor);
      }
 else {
        propertyTypes[0]=FeatureOperations.compound(name(AttributeConvention.IDENTIFIER_PROPERTY),idDelimiter,idPrefix,idSuffix,identifierTypes);
      }
    }
    feature=new DefaultFeatureType(identification(),isAbstract(),superTypes.toArray(new FeatureType[superTypes.size()]),ArraysExt.resize(propertyTypes,propertyCursor));
  }
  return feature;
}