Program: 92106
Project: 92106
Buggy source:
/** 
 * Formats this parameter as a <cite>Well Known Text</cite>   {@code Parameter[…]} element.Example: {@preformat wktParameter["False easting", 0.0, LengthUnit["metre", 1]]}<div class="note"><b>Compatibility note:</b> Version 1 of WKT format did not specified the parameter unit explicitely. Instead, the unit was inherited from the enclosing element.</div>
 * @param formatter The formatter where to format the inner content of this WKT element.
 * @return {@code "Parameter"} or {@code "ParameterFile"}.
 * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#119">WKT 2 specification</a>
 */
@Override protected String formatTo(final Formatter formatter){
  final ParameterDescriptor<T> descriptor=getDescriptor();
  WKTUtilities.appendName(descriptor,formatter,ElementKind.PARAMETER);
  final Unit<?> targetUnit=formatter.toContextualUnit(descriptor.getUnit());
  final Convention convention=formatter.getConvention();
  final boolean isWKT1=convention.majorVersion() == 1;
  final Unit<?> unit=getUnit();
  if (isWKT1 && targetUnit != null) {
    double convertedValue;
    try {
      convertedValue=doubleValue(targetUnit);
    }
 catch (    IllegalStateException exception) {
      formatter.setInvalidWKT(descriptor,exception);
      convertedValue=Double.NaN;
    }
    formatter.append(convertedValue);
  }
 else {
    final T value=getValue();
    if (!isWKT1 && (unit == null) && (value instanceof URI || value instanceof URL || value instanceof File|| value instanceof Path)) {
      formatter.append(value.toString(),null);
      return WKTKeywords.ParameterFile;
    }
    formatter.appendAny(value);
  }
  if (unit != null && !isWKT1 && (!convention.isSimplified() || !unit.equals(targetUnit))) {
    formatter.append(unit);
  }
  return WKTKeywords.Parameter;
}

Fixed version (ground truth):
/** 
 * Formats this parameter as a <cite>Well Known Text</cite>   {@code Parameter[…]} element.Example: {@preformat wktParameter["False easting", 0.0, LengthUnit["metre", 1]]}<div class="section">Unit of measurement</div> The units of measurement were never specified in WKT 1 format, and are optional in WKT 2 format. If the units are not specified, then they are inferred from the context. Typically, parameter values that are lengths are given in the unit for the projected CRS axes while parameter values that are angles are given in the unit for the base geographic CRS. <div class="note"><b>Example:</b> The snippet below show WKT representations of the map projection parameters of a projected CRS (most other elements are omitted). The map projection uses a <cite>"Latitude of natural origin"</cite> parameters which is set to 52 <strong>grads</strong>, as defined in the   {@code UNIT[…]} element of theenclosing CRS. A similar rule applies to <cite>“False easting”</cite> and <cite>“False northing”</cite> parameters, which are in kilometres in this example. <p><b>WKT 1:</b></p> {@preformat wktPROJCS[…, GEOGCS[…, UNIT[“grad”, 0.015707963267948967]],       // Unit for all angles PROJECTION[“Lambert_Conformal_Conic_1SP”] PARAMETER[“latitude_of_origin”, 52.0],       // In grads PARAMETER[“scale_factor”, 0.99987742], PARAMETER[“false_easting”, 600.0],           // In kilometres PARAMETER[“false_northing”, 2200.0],         // In kilometres UNIT[“km”, 1000]]                            // Unit for all lengths}<p><b>WKT 2:</b></p>  {@preformat wktProjectedCRS[… BaseGeodCRS[… AngleUnit[“grad”, 0.015707963267948967]], Conversion["Lambert zone II", Method["Lambert Conic Conformal (1SP)"], Parameter["Latitude of natural origin", 52.0], Parameter["Scale factor at natural origin", 0.99987742], Parameter["False easting", 600.0], Parameter["False northing", 2200.0]], CS["Cartesian", 2], LengthUnit["km", 1000]]}</div>
 * @param formatter The formatter where to format the inner content of this WKT element.
 * @return {@code "Parameter"} or {@code "ParameterFile"}.
 * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#119">WKT 2 specification</a>
 */
@Override protected String formatTo(final Formatter formatter){
  final ParameterDescriptor<T> descriptor=getDescriptor();
  WKTUtilities.appendName(descriptor,formatter,ElementKind.PARAMETER);
  final Unit<?> targetUnit=formatter.toContextualUnit(descriptor.getUnit());
  final Convention convention=formatter.getConvention();
  final boolean isWKT1=convention.majorVersion() == 1;
  final T value=getValue();
  final Unit<?> unit=getUnit();
  double convertedValue=Double.NaN;
  boolean sameUnit=Objects.equals(unit,targetUnit);
  if (!sameUnit)   try {
    convertedValue=doubleValue(targetUnit);
    sameUnit=(value instanceof Number) && ((Number)value).doubleValue() == convertedValue;
  }
 catch (  IllegalStateException exception) {
    formatter.setInvalidWKT(descriptor,exception);
  }
  if (isWKT1 && !sameUnit) {
    formatter.append(convertedValue);
  }
 else   if (!isWKT1 && (unit == null) && isFile(value)) {
    formatter.append(value.toString(),null);
    return WKTKeywords.ParameterFile;
  }
 else {
    formatter.appendAny(value);
  }
  if (!isWKT1 && (!sameUnit || !convention.isSimplified() || !hasContextualUnit(formatter))) {
    formatter.append(unit);
  }
  return WKTKeywords.Parameter;
}