Program: 91980
Project: 91980
Buggy source:
/** 
 * Creates an arbitrary datum from a code. The returned object will typically be an instance of   {@link GeodeticDatum},   {@link VerticalDatum} or {@link TemporalDatum}. <div class="note"><b>Example:</b> some EPSG codes for datums are: <table class="sis" summary="EPSG codes examples"> <tr><th>Code</th> <th>Type</th>        <th>Description</th></tr> <tr><td>6326</td> <td>Geodetic</td>    <td>World Geodetic System 1984</td></tr> <tr><td>6322</td> <td>Geodetic</td>    <td>World Geodetic System 1972</td></tr> <tr><td>1027</td> <td>Vertical</td>    <td>EGM2008 geoid</td></tr> <tr><td>5100</td> <td>Vertical</td>    <td>Mean Sea Level</td></tr> <tr><td>9315</td> <td>Engineering</td> <td>Seismic bin grid datum</td></tr> </table></div>
 * @param code Value allocated by EPSG.
 * @return The datum for the given code.
 * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
 * @throws FactoryException if the object creation failed for some other reason.
 * @todo Current implementation maps all "vertical" datum to {@link VerticalDatumType#GEOIDAL}. We do not know yet how to maps the exact vertical datum type from the EPSG database.
 */
@Override public synchronized Datum createDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
  ArgumentChecks.ensureNonNull("String_Node_Str",code);
  Datum returnValue=null;
  try (ResultSet result=executeQuery("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",code)){
    while (result.next()) {
      final Integer epsg=getInteger(code,result,1);
      final String name=getString(code,result,2);
      final String type=getString(code,result,3);
      final String anchor=getOptionalString(result,4);
      final String epoch=getOptionalString(result,5);
      final String area=getOptionalString(result,6);
      final String scope=getOptionalString(result,7);
      final String remarks=getOptionalString(result,8);
      final boolean deprecated=getOptionalBoolean(result,9);
      Map<String,Object> properties=createProperties("String_Node_Str",name,epsg,area,scope,remarks,deprecated);
      if (anchor != null) {
        properties.put(Datum.ANCHOR_POINT_KEY,anchor);
      }
      if (epoch != null && !epoch.isEmpty())       try {
        final int year=Integer.parseInt(epoch);
        final Calendar calendar=getCalendar();
        calendar.set(year,0,1);
        properties.put(Datum.REALIZATION_EPOCH_KEY,calendar.getTime());
      }
 catch (      NumberFormatException exception) {
        unexpectedException("String_Node_Str",exception);
      }
      final DatumFactory datumFactory=parent.datumFactory;
      final Datum datum;
switch (type.toLowerCase(Locale.US)) {
case "String_Node_Str":
{
          properties=new HashMap<>(properties);
          final Ellipsoid ellipsoid=parent.createEllipsoid(getString(code,result,10));
          final PrimeMeridian meridian=parent.createPrimeMeridian(getString(code,result,11));
          final BursaWolfParameters[] param=createBursaWolfParameters(epsg);
          if (param != null) {
            properties.put(DefaultGeodeticDatum.BURSA_WOLF_KEY,param);
          }
          datum=datumFactory.createGeodeticDatum(properties,ellipsoid,meridian);
          break;
        }
case "String_Node_Str":
{
        datum=datumFactory.createVerticalDatum(properties,VerticalDatumType.GEOIDAL);
        break;
      }
case "String_Node_Str":
{
      final Date originDate;
      if (anchor == null || anchor.isEmpty()) {
        throw new FactoryDataException(error().getString(Errors.Keys.DatumOriginShallBeDate));
      }
      if (dateFormat == null) {
        dateFormat=new SimpleDateFormat("String_Node_Str",Locale.CANADA);
        dateFormat.setCalendar(getCalendar());
      }
      try {
        originDate=dateFormat.parse(anchor);
      }
 catch (      ParseException e) {
        throw new FactoryDataException(error().getString(Errors.Keys.DatumOriginShallBeDate),e);
      }
      datum=datumFactory.createTemporalDatum(properties,originDate);
      break;
    }
case "String_Node_Str":
{
    datum=datumFactory.createEngineeringDatum(properties);
    break;
  }
default :
{
  throw new FactoryDataException(error().getString(Errors.Keys.UnknownType_1,type));
}
}
returnValue=ensureSingleton(datum,returnValue,code);
}
}
 catch (SQLException exception) {
throw databaseFailure(Datum.class,code,exception);
}
if (returnValue == null) {
throw noSuchAuthorityCode(Datum.class,code);
}
return returnValue;
}

Fixed version (ground truth):
/** 
 * Creates an arbitrary datum from a code. The returned object will typically be an instance of   {@link GeodeticDatum},   {@link VerticalDatum} or {@link TemporalDatum}. <div class="note"><b>Example:</b> some EPSG codes for datums are: <table class="sis" summary="EPSG codes examples"> <tr><th>Code</th> <th>Type</th>        <th>Description</th></tr> <tr><td>6326</td> <td>Geodetic</td>    <td>World Geodetic System 1984</td></tr> <tr><td>6322</td> <td>Geodetic</td>    <td>World Geodetic System 1972</td></tr> <tr><td>1027</td> <td>Vertical</td>    <td>EGM2008 geoid</td></tr> <tr><td>5100</td> <td>Vertical</td>    <td>Mean Sea Level</td></tr> <tr><td>9315</td> <td>Engineering</td> <td>Seismic bin grid datum</td></tr> </table></div>
 * @param code Value allocated by EPSG.
 * @return The datum for the given code.
 * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
 * @throws FactoryException if the object creation failed for some other reason.
 * @todo Current implementation maps all "vertical" datum to {@link VerticalDatumType#GEOIDAL}. We do not know yet how to maps the exact vertical datum type from the EPSG database.
 */
@Override public synchronized Datum createDatum(final String code) throws NoSuchAuthorityCodeException, FactoryException {
  ArgumentChecks.ensureNonNull("String_Node_Str",code);
  Datum returnValue=null;
  try (ResultSet result=executeQuery("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",code)){
    while (result.next()) {
      final Integer epsg=getInteger(code,result,1);
      final String name=getString(code,result,2);
      final String type=getString(code,result,3);
      final String anchor=getOptionalString(result,4);
      final String epoch=getOptionalString(result,5);
      final String area=getOptionalString(result,6);
      final String scope=getOptionalString(result,7);
      final String remarks=getOptionalString(result,8);
      final boolean deprecated=getOptionalBoolean(result,9);
      Map<String,Object> properties=createProperties("String_Node_Str",name,epsg,area,scope,remarks,deprecated);
      if (anchor != null) {
        properties.put(Datum.ANCHOR_POINT_KEY,anchor);
      }
      if (epoch != null && !epoch.isEmpty())       try {
        final int year=Integer.parseInt(epoch);
        final Calendar calendar=getCalendar();
        calendar.set(year,0,1);
        properties.put(Datum.REALIZATION_EPOCH_KEY,calendar.getTime());
      }
 catch (      NumberFormatException exception) {
        unexpectedException("String_Node_Str",exception);
      }
      final DatumFactory datumFactory=parent.datumFactory;
      final Datum datum;
switch (type.toLowerCase(Locale.US)) {
case "String_Node_Str":
{
          properties=new HashMap<>(properties);
          final Ellipsoid ellipsoid=parent.createEllipsoid(getString(code,result,10));
          final PrimeMeridian meridian=parent.createPrimeMeridian(getString(code,result,11));
          final BursaWolfParameters[] param=createBursaWolfParameters(epsg);
          if (param != null) {
            properties.put(DefaultGeodeticDatum.BURSA_WOLF_KEY,param);
          }
          datum=datumFactory.createGeodeticDatum(properties,ellipsoid,meridian);
          break;
        }
case "String_Node_Str":
{
        datum=datumFactory.createVerticalDatum(properties,VerticalDatumType.GEOIDAL);
        break;
      }
case "String_Node_Str":
{
      final Date originDate;
      if (anchor == null || anchor.isEmpty()) {
        throw new FactoryDataException(error().getString(Errors.Keys.DatumOriginShallBeDate));
      }
      if (dateFormat == null) {
        dateFormat=new SimpleDateFormat("String_Node_Str",Locale.CANADA);
        dateFormat.setCalendar(getCalendar());
      }
      try {
        originDate=dateFormat.parse(anchor);
      }
 catch (      ParseException e) {
        throw new FactoryDataException(error().getString(Errors.Keys.DatumOriginShallBeDate),e);
      }
      datum=datumFactory.createTemporalDatum(properties,originDate);
      break;
    }
case "String_Node_Str":
{
    datum=datumFactory.createEngineeringDatum(properties);
    break;
  }
default :
{
  throw new FactoryDataException(error().getString(Errors.Keys.UnknownType_1,type));
}
}
returnValue=ensureSingleton(datum,returnValue,code);
if (result.isClosed()) {
break;
}
}
}
 catch (SQLException exception) {
throw databaseFailure(Datum.class,code,exception);
}
if (returnValue == null) {
throw noSuchAuthorityCode(Datum.class,code);
}
return returnValue;
}