Program: 91937
Project: 91937
Buggy source:
/** 
 * Parses a   {@code "VerticalCRS"} (WKT 2) element. The syntax is given by<a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#69">WKT 2 specification §10</a>. The legacy WKT 1 pattern was: {@preformat text}VERT_CS["<name>", <vert datum>, <linear unit>,  <axis>,} {,<authority>}] }
 * @param mode      {@link #FIRST},   {@link #OPTIONAL} or {@link #MANDATORY}.
 * @param parent    The parent element.
 * @param isBaseCRS {@code true} if parsing the CRS inside a {@code DerivedCRS}.
 * @return The {@code "VerticalCRS"} element as a {@link VerticalCRS} object.
 * @throws ParseException if the {@code "VerticalCRS"} element can not be parsed.
 */
private SingleCRS parseVerticalCRS(final int mode,final Element parent,final boolean isBaseCRS) throws ParseException {
  final Element element=parent.pullElement(mode,isBaseCRS ? new String[]{WKTKeywords.BaseVertCRS} : new String[]{WKTKeywords.VerticalCRS,WKTKeywords.VertCRS,WKTKeywords.Vert_CS});
  if (element == null) {
    return null;
  }
  final boolean isWKT1=element.getKeywordIndex() == 2;
  final String name=element.pullString("String_Node_Str");
  final Unit<?> unit=parseUnit(element);
  VerticalDatum datum=null;
  SingleCRS baseCRS=null;
  Conversion fromBase=null;
  if (!isWKT1 && !isBaseCRS) {
    fromBase=parseDerivingConversion(OPTIONAL,element,WKTKeywords.DerivingConversion,unit,null);
    if (fromBase != null) {
      baseCRS=parseVerticalCRS(MANDATORY,element,true);
    }
  }
  if (baseCRS == null) {
    datum=parseVerticalDatum(MANDATORY,element,isWKT1);
  }
  final CoordinateSystem cs;
  try {
    cs=parseCoordinateSystem(element,WKTKeywords.vertical,1,isWKT1,unit,datum);
    final Map<String,?> properties=parseMetadataAndClose(element,name,datum);
    if (cs instanceof VerticalCS) {
      if (baseCRS != null) {
        return crsFactory.createDerivedCRS(properties,baseCRS,fromBase,cs);
      }
      if (VerticalDatumType.OTHER_SURFACE.equals(datum.getVerticalDatumType())) {
        final VerticalDatumType type=VerticalDatumTypes.guess(datum.getName().getCode(),datum.getAlias(),cs.getAxis(0));
        if (!VerticalDatumType.OTHER_SURFACE.equals(type)) {
          datum=datumFactory.createVerticalDatum(referencing.getProperties(datum),type);
        }
      }
      verticalCRS=crsFactory.createVerticalCRS(properties,datum,(VerticalCS)cs);
      if (verticalElements != null) {
        verticalElements=verticalElements.resolve(verticalCRS);
      }
      return verticalCRS;
    }
  }
 catch (  FactoryException exception) {
    throw element.parseFailed(exception);
  }
  throw element.illegalCS(cs);
}

Fixed version (ground truth):
/** 
 * Parses a   {@code "VerticalCRS"} (WKT 2) element. The syntax is given by<a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#69">WKT 2 specification §10</a>. The legacy WKT 1 pattern was: {@preformat wkt}VERT_CS["<name>", <vert datum>, <linear unit>,  <axis>,} {,<authority>}] }
 * @param mode      {@link #FIRST},   {@link #OPTIONAL} or {@link #MANDATORY}.
 * @param parent    The parent element.
 * @param isBaseCRS {@code true} if parsing the CRS inside a {@code DerivedCRS}.
 * @return The {@code "VerticalCRS"} element as a {@link VerticalCRS} object.
 * @throws ParseException if the {@code "VerticalCRS"} element can not be parsed.
 */
private SingleCRS parseVerticalCRS(final int mode,final Element parent,final boolean isBaseCRS) throws ParseException {
  final Element element=parent.pullElement(mode,isBaseCRS ? new String[]{WKTKeywords.BaseVertCRS} : new String[]{WKTKeywords.VerticalCRS,WKTKeywords.VertCRS,WKTKeywords.Vert_CS});
  if (element == null) {
    return null;
  }
  final boolean isWKT1=element.getKeywordIndex() == 2;
  final String name=element.pullString("String_Node_Str");
  final Unit<?> unit=parseUnit(element);
  VerticalDatum datum=null;
  SingleCRS baseCRS=null;
  Conversion fromBase=null;
  if (!isWKT1 && !isBaseCRS) {
    fromBase=parseDerivingConversion(OPTIONAL,element,WKTKeywords.DerivingConversion,unit,null);
    if (fromBase != null) {
      baseCRS=parseVerticalCRS(MANDATORY,element,true);
    }
  }
  if (baseCRS == null) {
    datum=parseVerticalDatum(MANDATORY,element,isWKT1);
  }
  final CoordinateSystem cs;
  try {
    cs=parseCoordinateSystem(element,WKTKeywords.vertical,1,isWKT1,unit,datum);
    final Map<String,?> properties=parseMetadataAndClose(element,name,datum);
    if (cs instanceof VerticalCS) {
      if (baseCRS != null) {
        return crsFactory.createDerivedCRS(properties,baseCRS,fromBase,cs);
      }
      if (VerticalDatumType.OTHER_SURFACE.equals(datum.getVerticalDatumType())) {
        final VerticalDatumType type=VerticalDatumTypes.guess(datum.getName().getCode(),datum.getAlias(),cs.getAxis(0));
        if (!VerticalDatumType.OTHER_SURFACE.equals(type)) {
          datum=datumFactory.createVerticalDatum(referencing.getProperties(datum),type);
        }
      }
      verticalCRS=crsFactory.createVerticalCRS(properties,datum,(VerticalCS)cs);
      if (verticalElements != null) {
        verticalElements=verticalElements.resolve(verticalCRS);
      }
      return verticalCRS;
    }
  }
 catch (  FactoryException exception) {
    throw element.parseFailed(exception);
  }
  throw element.illegalCS(cs);
}