Program: 92260
Project: 92260
Buggy source:
/** 
 * Appends the optional complementary attributes common to many   {@link IdentifiedObject} subtypes.Those attributes are  {@code ANCHOR},   {@code SCOPE},   {@code AREA},   {@code BBOX},   {@code VERTICALEXTENT},  {@code TIMEEXTENT},   {@code ID} (previously known as {@code AUTHORITY}) and   {@code REMARKS}, and have a special treatment: they are written by   {@link #append(FormattableObject))}after the   {@code formatTo(Formatter)} method returned.<p>The  {@code ID[<name>,<code>,…]} element is written only for the root element, unless the convention areINTERNAL. If formatted, the ID element will be on the same line than the enclosing one if no line separator were requested (e.g. SPHEROID["Clarke 1866", …, ID["EPSG", 7008]]), or on a new line otherwise. Example:</p> {@preformat textPROJCS["NAD27 / Idaho Central", GEOGCS[...etc...], ...etc... ID["EPSG", 26769]]}For non-internal conventions, all elements other than   {@code ID[…]} are formattedonly for  {@link CoordinateOperation} and {@link ReferenceSystem} types.In the later case, we also require that the CRS is not the base of a derived CRS. Those restrictions are our interpretation of the following ISO 19162 requirement: <blockquote>(…snip…)  {@code <scope extent identifier remark>} is a collection of four optional attributeswhich may be applied to a coordinate reference system, a coordinate operation or a boundCRS. (…snip…) Identifier (…snip…) may also be utilised for components of these objects although this is not recommended except for coordinate operation methods (including map projections) and parameters. (…snip…) A  {@code <remark>} can be included within the descriptions of source and target CRS embedded withina coordinate transformation as well as within the coordinate transformation itself.</blockquote>
 */
private void appendComplement(final IdentifiedObject object,final boolean isRoot){
  isComplement=true;
  final boolean showIDs;
  final boolean filterID;
  final boolean showOthers;
  if (convention == Convention.INTERNAL) {
    showIDs=true;
    filterID=false;
    showOthers=true;
  }
 else {
    if (convention == Convention.WKT2_SIMPLIFIED) {
      showIDs=isRoot;
    }
 else {
      showIDs=isRoot || (object instanceof OperationMethod) || (object instanceof GeneralParameterDescriptor);
    }
    if (convention.majorVersion() == 1) {
      filterID=true;
      showOthers=false;
    }
 else {
      filterID=!isRoot;
      if (object instanceof CoordinateOperation) {
        showOthers=true;
      }
 else       if (object instanceof ReferenceSystem) {
        showOthers=!(getEnclosingElement(1) instanceof ReferenceSystem);
      }
 else {
        showOthers=false;
      }
    }
  }
  if (showOthers) {
    appendForSubtypes(object);
  }
  if (showIDs) {
    Collection<ReferenceIdentifier> identifiers=object.getIdentifiers();
    if (identifiers != null) {
      if (filterID) {
        for (        final ReferenceIdentifier id : identifiers) {
          if (Citations.identifierMatches(authority,id.getAuthority())) {
            identifiers=Collections.singleton(id);
            break;
          }
        }
      }
      for (      ReferenceIdentifier id : identifiers) {
        if (!(id instanceof FormattableObject)) {
          id=ImmutableIdentifier.castOrCopy(id);
        }
        append((FormattableObject)id);
        if (filterID)         break;
      }
    }
  }
  if (showOthers) {
    appendOnNewLine("String_Node_Str",object.getRemarks(),ElementKind.REMARKS);
  }
  isComplement=false;
}

Fixed version (ground truth):
/** 
 * Appends the optional complementary attributes common to many   {@link IdentifiedObject} subtypes.Those attributes are  {@code ANCHOR},   {@code SCOPE},   {@code AREA},   {@code BBOX},   {@code VERTICALEXTENT},  {@code TIMEEXTENT},   {@code ID} (previously known as {@code AUTHORITY}) and   {@code REMARKS}, and have a special treatment: they are written by   {@link #append(FormattableObject)}after the   {@code formatTo(Formatter)} method returned.<p>The  {@code ID[<name>,<code>,…]} element is written only for the root element, unless the convention areINTERNAL. If formatted, the ID element will be on the same line than the enclosing one if no line separator were requested (e.g. SPHEROID["Clarke 1866", …, ID["EPSG", 7008]]), or on a new line otherwise. Example:</p> {@preformat textPROJCS["NAD27 / Idaho Central", GEOGCS[...etc...], ...etc... ID["EPSG", 26769]]}For non-internal conventions, all elements other than   {@code ID[…]} are formattedonly for  {@link CoordinateOperation} and {@link ReferenceSystem} types.In the later case, we also require that the CRS is not the base of a derived CRS. Those restrictions are our interpretation of the following ISO 19162 requirement: <blockquote>(…snip…)  {@code <scope extent identifier remark>} is a collection of four optional attributeswhich may be applied to a coordinate reference system, a coordinate operation or a boundCRS. (…snip…) Identifier (…snip…) may also be utilised for components of these objects although this is not recommended except for coordinate operation methods (including map projections) and parameters. (…snip…) A  {@code <remark>} can be included within the descriptions of source and target CRS embedded withina coordinate transformation as well as within the coordinate transformation itself.</blockquote>
 */
private void appendComplement(final IdentifiedObject object,final boolean isRoot){
  isComplement=true;
  final boolean showIDs;
  final boolean filterID;
  final boolean showOthers;
  if (convention == Convention.INTERNAL) {
    showIDs=true;
    filterID=false;
    showOthers=true;
  }
 else {
    if (convention == Convention.WKT2_SIMPLIFIED) {
      showIDs=isRoot;
    }
 else {
      showIDs=isRoot || (object instanceof OperationMethod) || (object instanceof GeneralParameterDescriptor);
    }
    if (convention.majorVersion() == 1) {
      filterID=true;
      showOthers=false;
    }
 else {
      filterID=!isRoot;
      if (object instanceof CoordinateOperation) {
        showOthers=true;
      }
 else       if (object instanceof ReferenceSystem) {
        showOthers=!(getEnclosingElement(1) instanceof ReferenceSystem);
      }
 else {
        showOthers=false;
      }
    }
  }
  if (showOthers) {
    appendForSubtypes(object);
  }
  if (showIDs) {
    Collection<ReferenceIdentifier> identifiers=object.getIdentifiers();
    if (identifiers != null) {
      if (filterID) {
        for (        final ReferenceIdentifier id : identifiers) {
          if (Citations.identifierMatches(authority,id.getAuthority())) {
            identifiers=Collections.singleton(id);
            break;
          }
        }
      }
      for (      ReferenceIdentifier id : identifiers) {
        if (!(id instanceof FormattableObject)) {
          id=ImmutableIdentifier.castOrCopy(id);
        }
        append((FormattableObject)id);
        if (filterID)         break;
      }
    }
  }
  if (showOthers) {
    appendOnNewLine("String_Node_Str",object.getRemarks(),ElementKind.REMARKS);
  }
  isComplement=false;
}