Program: 92056
Project: 92056
Buggy source:
/** 
 * Formats the given object to the given stream of buffer. The object may be an instance of any of the following types: <ul> <li>  {@link Feature}</li> <li>  {@link FeatureType}</li> </ul>
 * @throws IOException If an error occurred while writing to the given appendable.
 */
@Override public void format(final Object object,final Appendable toAppendTo) throws IOException {
  ArgumentChecks.ensureNonNull("String_Node_Str",object);
  ArgumentChecks.ensureNonNull("String_Node_Str",toAppendTo);
  final FeatureType featureType;
  final Feature feature;
  if (object instanceof Feature) {
    feature=(Feature)object;
    featureType=feature.getType();
  }
 else   if (object instanceof FeatureType) {
    featureType=(FeatureType)object;
    feature=null;
  }
 else {
    throw new IllegalArgumentException(Errors.getResources(displayLocale).getString(Errors.Keys.UnsupportedType_1,object.getClass()));
  }
  boolean hasCharacteristics=false;
  for (  final PropertyType propertyType : featureType.getProperties(true)) {
    if (propertyType instanceof AttributeType<?>) {
      if (!((AttributeType<?>)propertyType).characteristics().isEmpty()) {
        hasCharacteristics=true;
        break;
      }
    }
  }
  toAppendTo.append(toString(featureType.getName())).append(getLineSeparator());
  final Vocabulary resources=Vocabulary.getResources(displayLocale);
  final TableAppender table=new TableAppender(toAppendTo,columnSeparator);
  table.setMultiLinesCells(true);
  table.nextLine('─');
  header:   for (int i=0; ; i++) {
    final short key;
switch (i) {
case 0:
      key=Vocabulary.Keys.Name;
    break;
case 1:
  nextColumn(table);
key=Vocabulary.Keys.Type;
break;
case 2:
nextColumn(table);
key=Vocabulary.Keys.Cardinality;
break;
case 3:
nextColumn(table);
key=(feature != null) ? Vocabulary.Keys.Value : Vocabulary.Keys.DefaultValue;
break;
case 4:
{
if (hasCharacteristics) {
nextColumn(table);
key=Vocabulary.Keys.Characteristics;
break;
}
 else {
break header;
}
}
default :
break header;
}
table.append(resources.getString(key));
}
table.nextLine();
table.nextLine('─');
final StringBuffer buffer=new StringBuffer();
final FieldPosition dummyFP=new FieldPosition(-1);
for (final PropertyType propertyType : featureType.getProperties(true)) {
Object value;
if (feature != null) {
value=feature.getPropertyValue(propertyType.getName().toString());
if (value == null) {
if (propertyType instanceof AttributeType && ((AttributeType)propertyType).getMinimumOccurs() == 0) {
continue;
}
if (propertyType instanceof FeatureAssociationRole && ((FeatureAssociationRole)propertyType).getMinimumOccurs() == 0) {
continue;
}
}
}
 else if (propertyType instanceof AttributeType<?>) {
value=((AttributeType<?>)propertyType).getDefaultValue();
}
 else {
value=null;
}
table.append(toString(propertyType.getName()));
nextColumn(table);
final String valueType;
final Class<?> valueClass;
final int minimumOccurs, maximumOccurs;
if (propertyType instanceof AttributeType<?>) {
final AttributeType<?> pt=(AttributeType<?>)propertyType;
minimumOccurs=pt.getMinimumOccurs();
maximumOccurs=pt.getMaximumOccurs();
valueClass=pt.getValueClass();
valueType=getFormat(Class.class).format(valueClass,buffer,dummyFP).toString();
buffer.setLength(0);
}
 else if (propertyType instanceof FeatureAssociationRole) {
final FeatureAssociationRole pt=(FeatureAssociationRole)propertyType;
minimumOccurs=pt.getMinimumOccurs();
maximumOccurs=pt.getMaximumOccurs();
valueType=toString(DefaultAssociationRole.getValueTypeName(pt));
valueClass=Feature.class;
}
 else if (propertyType instanceof Operation) {
final IdentifiedType resultType=((Operation)propertyType).getResult();
valueType=toString(resultType.getName());
valueClass=null;
minimumOccurs=-1;
maximumOccurs=-1;
}
 else {
valueType="String_Node_Str";
valueClass=null;
minimumOccurs=-1;
maximumOccurs=-1;
}
table.append(valueType);
nextColumn(table);
if (maximumOccurs >= 0) {
final Format format=getFormat(Integer.class);
table.append('[').append(format.format(minimumOccurs,buffer,dummyFP)).append("String_Node_Str");
buffer.setLength(0);
if (maximumOccurs != Integer.MAX_VALUE) {
table.append(format.format(maximumOccurs,buffer,dummyFP));
}
 else {
table.append('∞');
}
buffer.setLength(0);
table.append(']');
}
nextColumn(table);
if (value != null) {
final Format format=getFormat(valueClass);
if (format != null) {
value=format.format(value,buffer,dummyFP);
}
 else if (value instanceof Feature && propertyType instanceof FeatureAssociationRole) {
final String p=DefaultAssociationRole.getTitleProperty((FeatureAssociationRole)propertyType);
if (p != null) {
value=((Feature)value).getPropertyValue(p);
}
}
if (value != null) {
table.append(formatValue(value));
}
buffer.setLength(0);
}
if (hasCharacteristics) {
nextColumn(table);
if (propertyType instanceof AttributeType<?>) {
String separator="String_Node_Str";
for (final AttributeType<?> attribute : ((AttributeType<?>)propertyType).characteristics().values()) {
table.append(separator).append(toString(attribute.getName()));
Object c=attribute.getDefaultValue();
if (feature != null) {
final Property p=feature.getProperty(propertyType.getName().toString());
if (p instanceof Attribute<?>) {
c=((Attribute<?>)p).characteristics().get(attribute.getName().toString());
}
}
if (c != null) {
table.append("String_Node_Str").append(formatValue(c));
}
separator="String_Node_Str";
}
}
}
table.nextLine();
}
table.nextLine('─');
table.flush();
}

Fixed version (ground truth):
/** 
 * Formats the given object to the given stream of buffer. The object may be an instance of any of the following types: <ul> <li>  {@link Feature}</li> <li>  {@link FeatureType}</li> </ul>
 * @throws IOException If an error occurred while writing to the given appendable.
 */
@Override public void format(final Object object,final Appendable toAppendTo) throws IOException {
  ArgumentChecks.ensureNonNull("String_Node_Str",object);
  ArgumentChecks.ensureNonNull("String_Node_Str",toAppendTo);
  final FeatureType featureType;
  final Feature feature;
  if (object instanceof Feature) {
    feature=(Feature)object;
    featureType=feature.getType();
  }
 else   if (object instanceof FeatureType) {
    featureType=(FeatureType)object;
    feature=null;
  }
 else {
    throw new IllegalArgumentException(Errors.getResources(displayLocale).getString(Errors.Keys.UnsupportedType_1,object.getClass()));
  }
  boolean hasCharacteristics=false;
  for (  final PropertyType propertyType : featureType.getProperties(true)) {
    if (propertyType instanceof AttributeType<?>) {
      if (!((AttributeType<?>)propertyType).characteristics().isEmpty()) {
        hasCharacteristics=true;
        break;
      }
    }
  }
  toAppendTo.append(toString(featureType.getName())).append(getLineSeparator());
  final Vocabulary resources=Vocabulary.getResources(displayLocale);
  final TableAppender table=new TableAppender(toAppendTo,columnSeparator);
  table.setMultiLinesCells(true);
  table.nextLine('─');
  header:   for (int i=0; ; i++) {
    final short key;
switch (i) {
case 0:
      key=Vocabulary.Keys.Name;
    break;
case 1:
  nextColumn(table);
key=Vocabulary.Keys.Type;
break;
case 2:
nextColumn(table);
key=Vocabulary.Keys.Cardinality;
break;
case 3:
nextColumn(table);
key=(feature != null) ? Vocabulary.Keys.Value : Vocabulary.Keys.DefaultValue;
break;
case 4:
{
if (hasCharacteristics) {
nextColumn(table);
key=Vocabulary.Keys.Characteristics;
break;
}
 else {
break header;
}
}
default :
break header;
}
table.append(resources.getString(key));
}
table.nextLine();
table.nextLine('─');
final StringBuffer buffer=new StringBuffer();
final FieldPosition dummyFP=new FieldPosition(-1);
for (final PropertyType propertyType : featureType.getProperties(true)) {
Object value;
if (feature != null) {
value=feature.getPropertyValue(propertyType.getName().toString());
if (value == null) {
if (propertyType instanceof AttributeType && ((AttributeType)propertyType).getMinimumOccurs() == 0) {
continue;
}
if (propertyType instanceof FeatureAssociationRole && ((FeatureAssociationRole)propertyType).getMinimumOccurs() == 0) {
continue;
}
}
}
 else if (propertyType instanceof AttributeType<?>) {
value=((AttributeType<?>)propertyType).getDefaultValue();
}
 else {
value=null;
}
table.append(toString(propertyType.getName()));
nextColumn(table);
final String valueType;
final Class<?> valueClass;
final int minimumOccurs, maximumOccurs;
if (propertyType instanceof AttributeType<?>) {
final AttributeType<?> pt=(AttributeType<?>)propertyType;
minimumOccurs=pt.getMinimumOccurs();
maximumOccurs=pt.getMaximumOccurs();
valueClass=pt.getValueClass();
valueType=getFormat(Class.class).format(valueClass,buffer,dummyFP).toString();
buffer.setLength(0);
}
 else if (propertyType instanceof FeatureAssociationRole) {
final FeatureAssociationRole pt=(FeatureAssociationRole)propertyType;
minimumOccurs=pt.getMinimumOccurs();
maximumOccurs=pt.getMaximumOccurs();
valueType=toString(DefaultAssociationRole.getValueTypeName(pt));
valueClass=Feature.class;
}
 else if (propertyType instanceof Operation) {
final IdentifiedType resultType=((Operation)propertyType).getResult();
valueType=toString(resultType.getName());
valueClass=null;
minimumOccurs=-1;
maximumOccurs=-1;
}
 else {
valueType="String_Node_Str";
valueClass=null;
minimumOccurs=-1;
maximumOccurs=-1;
}
table.append(valueType);
nextColumn(table);
if (maximumOccurs >= 0) {
final Format format=getFormat(Integer.class);
table.append('[').append(format.format(minimumOccurs,buffer,dummyFP)).append("String_Node_Str");
buffer.setLength(0);
if (maximumOccurs != Integer.MAX_VALUE) {
table.append(format.format(maximumOccurs,buffer,dummyFP));
}
 else {
table.append('∞');
}
buffer.setLength(0);
table.append(']');
}
nextColumn(table);
if (value != null) {
final boolean isInstance=valueClass != null && valueClass.isInstance(value);
final Format format=isInstance ? getFormat(valueClass) : null;
final Iterator<?> it=(!isInstance && (value instanceof Collection<?>) ? (Collection<?>)value : Collections.singleton(value)).iterator();
String separator="String_Node_Str";
while (it.hasNext()) {
value=it.next();
if (value != null) {
if (format != null) {
value=format.format(value,buffer,dummyFP);
}
 else if (value instanceof Feature && propertyType instanceof FeatureAssociationRole) {
final String p=DefaultAssociationRole.getTitleProperty((FeatureAssociationRole)propertyType);
if (p != null) {
value=((Feature)value).getPropertyValue(p);
if (value == null) continue;
}
}
table.append(separator).append(formatValue(value));
buffer.setLength(0);
separator="String_Node_Str";
}
}
}
if (hasCharacteristics) {
nextColumn(table);
if (propertyType instanceof AttributeType<?>) {
String separator="String_Node_Str";
for (final AttributeType<?> attribute : ((AttributeType<?>)propertyType).characteristics().values()) {
table.append(separator).append(toString(attribute.getName()));
Object c=attribute.getDefaultValue();
if (feature != null) {
final Property p=feature.getProperty(propertyType.getName().toString());
if (p instanceof Attribute<?>) {
c=((Attribute<?>)p).characteristics().get(attribute.getName().toString());
}
}
if (c != null) {
table.append("String_Node_Str").append(formatValue(c));
}
separator="String_Node_Str";
}
}
}
table.nextLine();
}
table.nextLine('─');
table.flush();
}