Program: 92070
Project: 92070
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 DefaultFeatureType featureType;
  final AbstractFeature feature;
  if (object instanceof AbstractFeature) {
    feature=(AbstractFeature)object;
    featureType=feature.getType();
  }
 else   if (object instanceof DefaultFeatureType) {
    featureType=(DefaultFeatureType)object;
    feature=null;
  }
 else {
    throw new IllegalArgumentException(Errors.getResources(displayLocale).getString(Errors.Keys.UnsupportedType_1,object.getClass()));
  }
  boolean hasCharacteristics=false;
  for (  final AbstractIdentifiedType propertyType : featureType.getProperties(true)) {
    if (propertyType instanceof DefaultAttributeType<?>) {
      if (!((DefaultAttributeType<?>)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 AbstractIdentifiedType propertyType : featureType.getProperties(true)) {
Object value;
if (feature != null) {
value=feature.getPropertyValue(propertyType.getName().toString());
if (value == null) {
if (propertyType instanceof FieldType && ((FieldType)propertyType).getMinimumOccurs() == 0) {
continue;
}
}
}
 else if (propertyType instanceof DefaultAttributeType<?>) {
value=((DefaultAttributeType<?>)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 DefaultAttributeType<?>) {
final DefaultAttributeType<?> pt=(DefaultAttributeType<?>)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 DefaultAssociationRole) {
final DefaultAssociationRole pt=(DefaultAssociationRole)propertyType;
minimumOccurs=pt.getMinimumOccurs();
maximumOccurs=pt.getMaximumOccurs();
valueType=toString(DefaultAssociationRole.getValueTypeName(pt));
valueClass=AbstractFeature.class;
}
 else if (propertyType instanceof AbstractOperation) {
final AbstractIdentifiedType resultType=((AbstractOperation)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 AbstractFeature && propertyType instanceof DefaultAssociationRole) {
final String p=DefaultAssociationRole.getTitleProperty((DefaultAssociationRole)propertyType);
if (p != null) {
value=((AbstractFeature)value).getPropertyValue(p);
}
}
if (value != null) {
table.append(formatValue(value));
}
buffer.setLength(0);
}
if (hasCharacteristics) {
nextColumn(table);
if (propertyType instanceof DefaultAttributeType<?>) {
String separator="String_Node_Str";
for (final DefaultAttributeType<?> attribute : ((DefaultAttributeType<?>)propertyType).characteristics().values()) {
table.append(separator).append(toString(attribute.getName()));
Object c=attribute.getDefaultValue();
if (feature != null) {
final Object p=feature.getProperty(propertyType.getName().toString());
if (p instanceof AbstractAttribute<?>) {
c=((AbstractAttribute<?>)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 DefaultFeatureType featureType;
  final AbstractFeature feature;
  if (object instanceof AbstractFeature) {
    feature=(AbstractFeature)object;
    featureType=feature.getType();
  }
 else   if (object instanceof DefaultFeatureType) {
    featureType=(DefaultFeatureType)object;
    feature=null;
  }
 else {
    throw new IllegalArgumentException(Errors.getResources(displayLocale).getString(Errors.Keys.UnsupportedType_1,object.getClass()));
  }
  boolean hasCharacteristics=false;
  for (  final AbstractIdentifiedType propertyType : featureType.getProperties(true)) {
    if (propertyType instanceof DefaultAttributeType<?>) {
      if (!((DefaultAttributeType<?>)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 AbstractIdentifiedType propertyType : featureType.getProperties(true)) {
Object value;
if (feature != null) {
value=feature.getPropertyValue(propertyType.getName().toString());
if (value == null) {
if (propertyType instanceof FieldType && ((FieldType)propertyType).getMinimumOccurs() == 0) {
continue;
}
}
}
 else if (propertyType instanceof DefaultAttributeType<?>) {
value=((DefaultAttributeType<?>)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 DefaultAttributeType<?>) {
final DefaultAttributeType<?> pt=(DefaultAttributeType<?>)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 DefaultAssociationRole) {
final DefaultAssociationRole pt=(DefaultAssociationRole)propertyType;
minimumOccurs=pt.getMinimumOccurs();
maximumOccurs=pt.getMaximumOccurs();
valueType=toString(DefaultAssociationRole.getValueTypeName(pt));
valueClass=AbstractFeature.class;
}
 else if (propertyType instanceof AbstractOperation) {
final AbstractIdentifiedType resultType=((AbstractOperation)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 AbstractFeature && propertyType instanceof DefaultAssociationRole) {
final String p=DefaultAssociationRole.getTitleProperty((DefaultAssociationRole)propertyType);
if (p != null) {
value=((AbstractFeature)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 DefaultAttributeType<?>) {
String separator="String_Node_Str";
for (final DefaultAttributeType<?> attribute : ((DefaultAttributeType<?>)propertyType).characteristics().values()) {
table.append(separator).append(toString(attribute.getName()));
Object c=attribute.getDefaultValue();
if (feature != null) {
final Object p=feature.getProperty(propertyType.getName().toString());
if (p instanceof AbstractAttribute<?>) {
c=((AbstractAttribute<?>)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();
}