Program: 92183
Project: 92183
Buggy source:
/** 
 * Implementation of public   {@code format(…)} methods for all content levels except {@code NAME_SUMMARY}.
 * @param name       The group name, usually {@code descriptor.getName().getCode()}.
 * @param descriptor The parameter descriptor, usually {@code values.getDescriptor()}.
 * @param values     The parameter values, or {@code null} if none.
 * @throws IOException If an error occurred while writing to the given appendable.
 */
private void format(final String name,final ParameterDescriptorGroup group,final ParameterValueGroup values,final Appendable out) throws IOException {
  final boolean isBrief=(contentLevel == ContentLevel.BRIEF);
  final boolean showObligation=!isBrief || (values == null);
  final boolean hasColors=(colors != null);
  final String lineSeparator=this.lineSeparator;
  final Map<String,Integer> remarks=new LinkedHashMap<>();
  final ParameterTableRow header=new ParameterTableRow(group,displayLocale,preferredCodespaces,remarks,isBrief);
  final String groupCodespace=header.getCodeSpace();
  int codespaceWidth=0;
  final Collection<?> elements=(values != null) ? values.values() : group.descriptors();
  final Map<GeneralParameterDescriptor,ParameterTableRow> descriptorValues=new LinkedHashMap<>(hashMapCapacity(elements.size()));
  List<Object> deferredGroups=null;
  for (  final Object element : elements) {
    final GeneralParameterValue parameter;
    final GeneralParameterDescriptor descriptor;
    if (values != null) {
      parameter=(GeneralParameterValue)element;
      descriptor=parameter.getDescriptor();
    }
 else {
      parameter=null;
      descriptor=(GeneralParameterDescriptor)element;
    }
    if (descriptor instanceof ParameterDescriptorGroup) {
      if (deferredGroups == null) {
        deferredGroups=new ArrayList<>(4);
      }
      deferredGroups.add(element);
      continue;
    }
    Object value=null;
    Unit<?> unit=null;
    if (parameter instanceof ParameterValue<?>) {
      final ParameterValue<?> p=(ParameterValue<?>)parameter;
      value=p.getValue();
      unit=p.getUnit();
    }
 else     if (descriptor instanceof ParameterDescriptor<?>) {
      final ParameterDescriptor<?> p=(ParameterDescriptor<?>)descriptor;
      value=p.getDefaultValue();
      unit=p.getUnit();
    }
    ParameterTableRow row=descriptorValues.get(descriptor);
    if (row == null) {
      row=new ParameterTableRow(descriptor,displayLocale,preferredCodespaces,remarks,isBrief);
      descriptorValues.put(descriptor,row);
      if (row.codespaceWidth > codespaceWidth) {
        codespaceWidth=row.codespaceWidth;
      }
    }
    row.addValue(value,unit);
  }
  int unitWidth=0;
  int valueDomainAlignment=0;
  boolean writeCodespaces=(groupCodespace == null);
  final StringBuffer buffer=new StringBuffer();
  final FieldPosition dummyFP=new FieldPosition(-1);
  for (  final Map.Entry<GeneralParameterDescriptor,ParameterTableRow> entry : descriptorValues.entrySet()) {
    final GeneralParameterDescriptor descriptor=entry.getKey();
    if (descriptor instanceof ParameterDescriptor<?>) {
      final ParameterTableRow row=entry.getValue();
      if (!writeCodespaces && !groupCodespace.equals(entry.getValue().getCodeSpace())) {
        writeCodespaces=true;
      }
      final Range<?> valueDomain=Parameters.getValueDomain((ParameterDescriptor<?>)descriptor);
      if (valueDomain != null) {
        final int p=row.setValueDomain(valueDomain,getFormat(Range.class),buffer);
        if (p > valueDomainAlignment) {
          valueDomainAlignment=p;
        }
      }
      row.expandSingleton();
      final int length=row.units.size();
      for (int i=0; i < length; i++) {
        final Object unit=row.units.get(i);
        if (unit != null) {
          if (getFormat(Unit.class).format(unit,buffer,dummyFP).length() != 0) {
            if (Character.isLetterOrDigit(buffer.codePointAt(0))) {
              buffer.insert(0,' ');
            }
          }
          final String symbol=buffer.toString();
          row.units.set(i,symbol);
          buffer.setLength(0);
          final int p=symbol.length();
          if (p > unitWidth) {
            unitWidth=p;
          }
        }
      }
    }
  }
  final Vocabulary resources=Vocabulary.getResources(displayLocale);
  header.writeIdentifiers(out,true,colors,false,lineSeparator);
  out.append(lineSeparator);
  final char horizontalBorder=isBrief ? '─' : '═';
  final TableAppender table=(isBrief || !columnSeparator.equals(SEPARATOR)) ? new TableAppender(out,columnSeparator) : new TableAppender(out);
  table.setMultiLinesCells(true);
  table.nextLine(horizontalBorder);
  int numColumnsBeforeValue=0;
  for (int i=0; ; i++) {
    boolean end=false;
    final short key;
switch (i) {
case 0:
{
        key=Vocabulary.Keys.Name;
        break;
      }
case 1:
{
      key=Vocabulary.Keys.Type;
      break;
    }
case 2:
{
    if (!showObligation) {
      continue;
    }
    key=Vocabulary.Keys.Obligation;
    break;
  }
case 3:
{
  key=Vocabulary.Keys.ValueDomain;
  break;
}
case 4:
{
key=(values == null) ? Vocabulary.Keys.DefaultValue : Vocabulary.Keys.Value;
end=true;
break;
}
default :
throw new AssertionError(i);
}
if (hasColors) table.append(X364.BOLD.sequence());
table.append(resources.getString(key));
if (hasColors) table.append(X364.NORMAL.sequence());
if (!writeCodespaces && i == 0) {
table.append("String_Node_Str").append(groupCodespace).append(')');
}
if (end) break;
nextColumn(table);
numColumnsBeforeValue++;
}
table.nextLine();
char horizontalLine=horizontalBorder;
for (final Map.Entry<GeneralParameterDescriptor,ParameterTableRow> entry : descriptorValues.entrySet()) {
if (horizontalLine != 0) {
table.nextLine('─');
}
horizontalLine=isBrief ? 0 : '─';
final ParameterTableRow row=entry.getValue();
row.codespaceWidth=codespaceWidth;
row.writeIdentifiers(table,writeCodespaces,null,hasColors,lineSeparator);
nextColumn(table);
final GeneralParameterDescriptor generalDescriptor=entry.getKey();
if (generalDescriptor instanceof ParameterDescriptor<?>) {
final ParameterDescriptor<?> descriptor=(ParameterDescriptor<?>)generalDescriptor;
final Class<?> valueClass=descriptor.getValueClass();
table.append(getFormat(Class.class).format(valueClass,buffer,dummyFP).toString());
nextColumn(table);
buffer.setLength(0);
if (showObligation) {
final int minimumOccurs=descriptor.getMinimumOccurs();
final int maximumOccurs=descriptor.getMaximumOccurs();
if (maximumOccurs == 1) {
table.append(resources.getString(minimumOccurs == 0 ? Vocabulary.Keys.Optional : Vocabulary.Keys.Mandatory));
}
 else {
final Format f=getFormat(Integer.class);
table.append(f.format(minimumOccurs,buffer,dummyFP).toString()).append("String_Node_Str");
buffer.setLength(0);
if (maximumOccurs == Integer.MAX_VALUE) {
table.append('∞');
}
 else {
table.append(f.format(maximumOccurs,buffer,dummyFP).toString());
buffer.setLength(0);
}
}
nextColumn(table);
}
final String valueDomain=row.valueDomain;
if (valueDomain != null) {
table.append(CharSequences.spaces(valueDomainAlignment - row.valueDomainAlignment)).append(valueDomain);
}
nextColumn(table);
table.setCellAlignment(TableAppender.ALIGN_RIGHT);
final int length=row.values.size();
for (int i=0; i < length; i++) {
Object value=row.values.get(i);
if (value != null) {
if (i != 0) {
final String ditto=resources.getString(Vocabulary.Keys.DittoMark);
table.nextLine();
table.setCellAlignment(TableAppender.ALIGN_CENTER);
for (int j=0; j < numColumnsBeforeValue; j++) {
  table.append(ditto);
  nextColumn(table);
}
table.setCellAlignment(TableAppender.ALIGN_RIGHT);
}
final Format format=getFormat(value.getClass());
if (format != null) {
value=format.format(value,buffer,dummyFP);
}
table.append(value.toString());
buffer.setLength(0);
int pad=unitWidth;
final String unit=(String)row.units.get(i);
if (unit != null) {
table.append(unit);
pad-=unit.length();
}
table.append(CharSequences.spaces(pad));
}
}
}
table.nextLine();
table.setCellAlignment(TableAppender.ALIGN_LEFT);
}
table.nextLine(horizontalBorder);
table.flush();
for (final Map.Entry<String,Integer> remark : remarks.entrySet()) {
ParameterTableRow.writeFootnoteNumber(out,remark.getValue());
out.append(' ').append(remark.getKey()).append(lineSeparator);
}
if (deferredGroups != null) {
for (final Object element : deferredGroups) {
final ParameterValueGroup value;
final ParameterDescriptorGroup descriptor;
if (element instanceof ParameterValueGroup) {
value=(ParameterValueGroup)element;
descriptor=value.getDescriptor();
}
 else {
value=null;
descriptor=(ParameterDescriptorGroup)element;
}
out.append(lineSeparator);
format(name + '/' + descriptor.getName().getCode(),descriptor,value,out);
}
}
}

Fixed version (ground truth):
/** 
 * Implementation of public   {@code format(…)} methods for all content levels except {@code NAME_SUMMARY}.
 * @param name       The group name, usually {@code descriptor.getName().getCode()}.
 * @param descriptor The parameter descriptor, usually {@code values.getDescriptor()}.
 * @param values     The parameter values, or {@code null} if none.
 * @throws IOException If an error occurred while writing to the given appendable.
 */
private void format(final String name,final ParameterDescriptorGroup group,final ParameterValueGroup values,final Appendable out) throws IOException {
  final boolean isBrief=(contentLevel == ContentLevel.BRIEF);
  final boolean showObligation=!isBrief || (values == null);
  final boolean hasColors=(colors != null);
  final String lineSeparator=this.lineSeparator;
  final Map<String,Integer> remarks=new LinkedHashMap<>();
  final ParameterTableRow header=new ParameterTableRow(group,displayLocale,preferredCodespaces,remarks,isBrief);
  final String groupCodespace=header.getCodeSpace();
  int codespaceWidth=0;
  final Collection<?> elements=(values != null) ? values.values() : group.descriptors();
  final Map<GeneralParameterDescriptor,ParameterTableRow> descriptorValues=new LinkedHashMap<>(hashMapCapacity(elements.size()));
  List<Object> deferredGroups=null;
  for (  final Object element : elements) {
    final GeneralParameterValue parameter;
    final GeneralParameterDescriptor descriptor;
    if (values != null) {
      parameter=(GeneralParameterValue)element;
      descriptor=parameter.getDescriptor();
    }
 else {
      parameter=null;
      descriptor=(GeneralParameterDescriptor)element;
    }
    if (descriptor instanceof ParameterDescriptorGroup) {
      if (deferredGroups == null) {
        deferredGroups=new ArrayList<>(4);
      }
      deferredGroups.add(element);
      continue;
    }
    Object value=null;
    Unit<?> unit=null;
    if (parameter instanceof ParameterValue<?>) {
      final ParameterValue<?> p=(ParameterValue<?>)parameter;
      value=p.getValue();
      unit=p.getUnit();
    }
 else     if (descriptor instanceof ParameterDescriptor<?>) {
      final ParameterDescriptor<?> p=(ParameterDescriptor<?>)descriptor;
      value=p.getDefaultValue();
      unit=p.getUnit();
    }
    ParameterTableRow row=descriptorValues.get(descriptor);
    if (row == null) {
      row=new ParameterTableRow(descriptor,displayLocale,preferredCodespaces,remarks,isBrief);
      descriptorValues.put(descriptor,row);
      if (row.codespaceWidth > codespaceWidth) {
        codespaceWidth=row.codespaceWidth;
      }
    }
    row.addValue(value,unit);
  }
  int unitWidth=0;
  int valueDomainAlignment=0;
  boolean writeCodespaces=(groupCodespace == null);
  final StringBuffer buffer=new StringBuffer();
  final FieldPosition dummyFP=new FieldPosition(-1);
  for (  final Map.Entry<GeneralParameterDescriptor,ParameterTableRow> entry : descriptorValues.entrySet()) {
    final GeneralParameterDescriptor descriptor=entry.getKey();
    if (descriptor instanceof ParameterDescriptor<?>) {
      final ParameterTableRow row=entry.getValue();
      if (!writeCodespaces && !groupCodespace.equals(entry.getValue().getCodeSpace())) {
        writeCodespaces=true;
      }
      final Range<?> valueDomain=Parameters.getValueDomain((ParameterDescriptor<?>)descriptor);
      if (valueDomain != null) {
        final int p=row.setValueDomain(valueDomain,getFormat(Range.class),buffer);
        if (p > valueDomainAlignment) {
          valueDomainAlignment=p;
        }
      }
      row.expandSingleton();
      final int length=row.units.size();
      for (int i=0; i < length; i++) {
        final Object unit=row.units.get(i);
        if (unit != null) {
          if (getFormat(Unit.class).format(unit,buffer,dummyFP).length() != 0) {
            if (Character.isLetterOrDigit(buffer.codePointAt(0))) {
              buffer.insert(0,' ');
            }
          }
          final String symbol=buffer.toString();
          row.units.set(i,symbol);
          buffer.setLength(0);
          final int p=symbol.length();
          if (p > unitWidth) {
            unitWidth=p;
          }
        }
      }
    }
  }
  final Vocabulary resources=Vocabulary.getResources(displayLocale);
  header.writeIdentifiers(out,true,colors,false,lineSeparator);
  out.append(lineSeparator);
  final char horizontalBorder=isBrief ? '─' : '═';
  final TableAppender table=(isBrief || !columnSeparator.equals(SEPARATOR)) ? new TableAppender(out,columnSeparator) : new TableAppender(out);
  table.setMultiLinesCells(true);
  table.nextLine(horizontalBorder);
  int numColumnsBeforeValue=0;
  for (int i=0; ; i++) {
    boolean end=false;
    final short key;
switch (i) {
case 0:
{
        key=Vocabulary.Keys.Name;
        break;
      }
case 1:
{
      key=Vocabulary.Keys.Type;
      break;
    }
case 2:
{
    if (!showObligation) {
      continue;
    }
    key=Vocabulary.Keys.Obligation;
    break;
  }
case 3:
{
  key=Vocabulary.Keys.ValueDomain;
  break;
}
case 4:
{
key=(values == null) ? Vocabulary.Keys.DefaultValue : Vocabulary.Keys.Value;
end=true;
break;
}
default :
throw new AssertionError(i);
}
if (hasColors) table.append(X364.BOLD.sequence());
table.append(resources.getString(key));
if (hasColors) table.append(X364.NORMAL.sequence());
if (!writeCodespaces && i == 0) {
table.append("String_Node_Str").append(groupCodespace).append(')');
}
if (end) break;
nextColumn(table);
numColumnsBeforeValue++;
}
table.nextLine();
char horizontalLine=horizontalBorder;
for (final Map.Entry<GeneralParameterDescriptor,ParameterTableRow> entry : descriptorValues.entrySet()) {
if (horizontalLine != 0) {
table.nextLine('─');
}
horizontalLine=isBrief ? 0 : '─';
final ParameterTableRow row=entry.getValue();
row.codespaceWidth=codespaceWidth;
row.writeIdentifiers(table,writeCodespaces,null,hasColors,lineSeparator);
nextColumn(table);
final GeneralParameterDescriptor generalDescriptor=entry.getKey();
if (generalDescriptor instanceof ParameterDescriptor<?>) {
final ParameterDescriptor<?> descriptor=(ParameterDescriptor<?>)generalDescriptor;
final Class<?> valueClass=descriptor.getValueClass();
table.append(getFormat(Class.class).format(valueClass,buffer,dummyFP).toString());
nextColumn(table);
buffer.setLength(0);
if (showObligation) {
final int minimumOccurs=descriptor.getMinimumOccurs();
final int maximumOccurs=descriptor.getMaximumOccurs();
if (maximumOccurs == 1) {
table.append(resources.getString(minimumOccurs == 0 ? Vocabulary.Keys.Optional : Vocabulary.Keys.Mandatory));
}
 else {
final Format f=getFormat(Integer.class);
table.append(f.format(minimumOccurs,buffer,dummyFP).toString()).append("String_Node_Str");
buffer.setLength(0);
if (maximumOccurs == Integer.MAX_VALUE) {
table.append('∞');
}
 else {
table.append(f.format(maximumOccurs,buffer,dummyFP).toString());
buffer.setLength(0);
}
}
nextColumn(table);
}
final String valueDomain=row.valueDomain;
if (valueDomain != null) {
table.append(CharSequences.spaces(valueDomainAlignment - row.valueDomainAlignment)).append(valueDomain);
}
nextColumn(table);
table.setCellAlignment(TableAppender.ALIGN_RIGHT);
final int length=row.values.size();
for (int i=0; i < length; i++) {
Object value=row.values.get(i);
if (value != null) {
if (i != 0) {
final String ditto=resources.getString(Vocabulary.Keys.DittoMark);
table.nextLine();
table.setCellAlignment(TableAppender.ALIGN_CENTER);
for (int j=0; j < numColumnsBeforeValue; j++) {
  table.append(ditto);
  nextColumn(table);
}
table.setCellAlignment(TableAppender.ALIGN_RIGHT);
}
final Format format=getFormat(value.getClass());
if (format != null) {
if (format instanceof NumberFormat && value instanceof Number) {
  configure((NumberFormat)format,Math.abs(((Number)value).doubleValue()));
}
value=format.format(value,buffer,dummyFP);
}
table.append(value.toString());
buffer.setLength(0);
int pad=unitWidth;
final String unit=(String)row.units.get(i);
if (unit != null) {
table.append(unit);
pad-=unit.length();
}
table.append(CharSequences.spaces(pad));
}
}
}
table.nextLine();
table.setCellAlignment(TableAppender.ALIGN_LEFT);
}
table.nextLine(horizontalBorder);
table.flush();
for (final Map.Entry<String,Integer> remark : remarks.entrySet()) {
ParameterTableRow.writeFootnoteNumber(out,remark.getValue());
out.append(' ').append(remark.getKey()).append(lineSeparator);
}
if (deferredGroups != null) {
for (final Object element : deferredGroups) {
final ParameterValueGroup value;
final ParameterDescriptorGroup descriptor;
if (element instanceof ParameterValueGroup) {
value=(ParameterValueGroup)element;
descriptor=value.getDescriptor();
}
 else {
value=null;
descriptor=(ParameterDescriptorGroup)element;
}
out.append(lineSeparator);
format(name + '/' + descriptor.getName().getCode(),descriptor,value,out);
}
}
}