Program: 92304
Project: 92304
Buggy source:
/** 
 * Constructs an identifier from a set of properties. Keys are strings from the table below. Keys are case-insensitive, and leading and trailing spaces are ignored. The map given in argument shall contains at least a   {@code "code"} property. Other properties listed inthe table below are optional. <table class="sis"> <tr> <th>Property name</th> <th>Value type</th> <th>Value given to</th> </tr> <tr> <td> {@value org.opengis.metadata.Identifier#CODE_KEY}</td> <td>  {@link String}</td> <td>  {@link #getCode()}</td> </tr> <tr> <td>  {@value org.opengis.referencing.ReferenceIdentifier#CODESPACE_KEY}</td> <td>  {@link String}</td> <td>  {@link #getCodeSpace()}</td> </tr> <tr> <td>  {@value org.opengis.metadata.Identifier#AUTHORITY_KEY}</td> <td>  {@link String} or {@link Citation}</td> <td>  {@link #getAuthority()}</td> </tr> <tr> <td>  {@value org.opengis.referencing.ReferenceIdentifier#VERSION_KEY}</td> <td>  {@link String}</td> <td>  {@link #getVersion()}</td> </tr> <tr> <td>  {@value org.opengis.referencing.IdentifiedObject#REMARKS_KEY}</td> <td>  {@link String} or {@link InternationalString}</td> <td>  {@link #getRemarks()}</td> </tr> </table>  {@code "remarks"} is a localizable attributes which may have a language and countrycode suffix. For example the  {@code "remarks_fr"} property stands for remarks in{@linkplain Locale#FRENCH French} and the {@code "remarks_fr_CA"} property standsfor remarks in  {@linkplain Locale#CANADA_FRENCH French Canadian}.
 * @param properties The properties to be given to this identifier.
 * @throws InvalidParameterValueException if a property has an invalid value.
 * @throws IllegalArgumentException if a property is invalid for some other reason.
 */
public ImmutableIdentifier(final Map<String,?> properties) throws IllegalArgumentException {
  ensureNonNull("String_Node_Str",properties);
  Object code=null;
  Object codeSpace=null;
  Object version=null;
  Object authority=null;
  Object remarks=null;
  DefaultInternationalString localized=null;
  for (  final Map.Entry<String,?> entry : properties.entrySet()) {
    String key=entry.getKey().trim().toLowerCase();
    Object value=entry.getValue();
{
      if (key.equals(CODE_KEY)) {
        code=value;
        continue;
      }
 else       if (key.equals(CODESPACE_KEY)) {
        codeSpace=value;
        continue;
      }
 else       if (key.equals(VERSION_KEY)) {
        version=value;
        continue;
      }
 else       if (key.equals(AUTHORITY_KEY)) {
        if (value instanceof String) {
          value=Citations.fromName((String)value);
        }
        authority=value;
        continue;
      }
 else       if (key.equals(REMARKS_KEY)) {
        if (value instanceof String) {
          value=new SimpleInternationalString((String)value);
        }
        remarks=value;
        continue;
      }
    }
    final Locale locale=Locales.parseSuffix(REMARKS_KEY,key);
    if (locale != null) {
      if (localized == null) {
        if (remarks instanceof DefaultInternationalString) {
          localized=(DefaultInternationalString)remarks;
        }
 else {
          localized=new DefaultInternationalString();
          if (remarks instanceof CharSequence) {
            localized.add(Locale.ROOT,remarks.toString());
            remarks=null;
          }
        }
      }
      localized.add(locale,(String)value);
    }
  }
  if (localized != null && !localized.getLocales().isEmpty()) {
    if (remarks == null) {
      remarks=localized;
    }
 else {
      Logging.log(ImmutableIdentifier.class,"String_Node_Str",Messages.getResources(null).getLogRecord(Level.WARNING,Messages.Keys.LocalesDiscarded));
    }
  }
  if (codeSpace == null && authority instanceof Citation) {
    codeSpace=Citations.getIdentifier((Citation)authority);
  }
  String key=null;
  Object value=null;
  try {
    key=CODE_KEY;
    this.code=(String)(value=code);
    key=VERSION_KEY;
    this.version=(String)(value=version);
    key=CODESPACE_KEY;
    this.codeSpace=(String)(value=codeSpace);
    key=AUTHORITY_KEY;
    this.authority=(Citation)(value=authority);
    key=REMARKS_KEY;
    this.remarks=(InternationalString)(value=remarks);
  }
 catch (  ClassCastException exception) {
    final InvalidParameterValueException e=new InvalidParameterValueException(Errors.format(Errors.Keys.IllegalArgumentValue_2,key,value),key,value);
    e.initCause(exception);
    throw e;
  }
  if (code == null) {
    throw new IllegalArgumentException(Errors.format(Errors.Keys.MissingValueForProperty_1,CODE_KEY));
  }
}

Fixed version (ground truth):
/** 
 * Constructs an identifier from a set of properties. Keys are strings from the table below. Keys are case-insensitive, and leading and trailing spaces are ignored. The map given in argument shall contains at least a   {@code "code"} property. Other properties listed inthe table below are optional. <table class="sis"> <tr> <th>Property name</th> <th>Value type</th> <th>Value given to</th> </tr> <tr> <td> {@value org.opengis.metadata.Identifier#CODE_KEY}</td> <td>  {@link String}</td> <td>  {@link #getCode()}</td> </tr> <tr> <td>  {@value org.opengis.referencing.ReferenceIdentifier#CODESPACE_KEY}</td> <td>  {@link String}</td> <td>  {@link #getCodeSpace()}</td> </tr> <tr> <td>  {@value org.opengis.metadata.Identifier#AUTHORITY_KEY}</td> <td>  {@link String} or {@link Citation}</td> <td>  {@link #getAuthority()}</td> </tr> <tr> <td>  {@value org.opengis.referencing.ReferenceIdentifier#VERSION_KEY}</td> <td>  {@link String}</td> <td>  {@link #getVersion()}</td> </tr> <tr> <td>  {@value org.opengis.referencing.IdentifiedObject#REMARKS_KEY}</td> <td>  {@link String} or {@link InternationalString}</td> <td>  {@link #getRemarks()}</td> </tr> </table>  {@code "remarks"} is a localizable attributes which may have a language and countrycode suffix. For example the  {@code "remarks_fr"} property stands for remarks in{@linkplain Locale#FRENCH French} and the {@code "remarks_fr_CA"} property standsfor remarks in  {@linkplain Locale#CANADA_FRENCH French Canadian}.
 * @param properties The properties to be given to this identifier.
 * @throws InvalidParameterValueException if a property has an invalid value.
 * @throws IllegalArgumentException if a property is invalid for some other reason.
 */
public ImmutableIdentifier(final Map<String,?> properties) throws IllegalArgumentException {
  ensureNonNull("String_Node_Str",properties);
  Object code=null;
  Object codeSpace=null;
  Object version=null;
  Object authority=null;
  Object remarks=null;
  DefaultInternationalString localized=null;
  for (  final Map.Entry<String,?> entry : properties.entrySet()) {
    String key=entry.getKey().trim().toLowerCase();
    Object value=entry.getValue();
{
      if (key.equals(CODE_KEY)) {
        code=value;
        continue;
      }
 else       if (key.equals(CODESPACE_KEY)) {
        codeSpace=value;
        continue;
      }
 else       if (key.equals(VERSION_KEY)) {
        version=value;
        continue;
      }
 else       if (key.equals(AUTHORITY_KEY)) {
        if (value instanceof String) {
          value=Citations.fromName((String)value);
        }
        authority=value;
        continue;
      }
 else       if (key.equals(REMARKS_KEY)) {
        if (value instanceof String) {
          value=new SimpleInternationalString((String)value);
        }
        remarks=value;
        continue;
      }
    }
    final Locale locale=Locales.parseSuffix(REMARKS_KEY,key);
    if (locale != null) {
      if (localized == null) {
        localized=new DefaultInternationalString();
      }
      localized.add(locale,(String)value);
    }
  }
  if (localized != null) {
    if (remarks == null) {
      remarks=localized;
    }
 else     if (remarks instanceof SimpleInternationalString) {
      localized.add(Locale.ROOT,remarks.toString());
      remarks=localized;
    }
 else {
      Logging.log(ImmutableIdentifier.class,"String_Node_Str",Messages.getResources(null).getLogRecord(Level.WARNING,Messages.Keys.LocalesDiscarded));
    }
  }
  if (codeSpace == null && authority instanceof Citation) {
    codeSpace=Citations.getIdentifier((Citation)authority);
  }
  String key=null;
  Object value=null;
  try {
    key=CODE_KEY;
    this.code=(String)(value=code);
    key=VERSION_KEY;
    this.version=(String)(value=version);
    key=CODESPACE_KEY;
    this.codeSpace=(String)(value=codeSpace);
    key=AUTHORITY_KEY;
    this.authority=(Citation)(value=authority);
    key=REMARKS_KEY;
    this.remarks=(InternationalString)(value=remarks);
  }
 catch (  ClassCastException exception) {
    final InvalidParameterValueException e=new InvalidParameterValueException(Errors.format(Errors.Keys.IllegalArgumentValue_2,key,value),key,value);
    e.initCause(exception);
    throw e;
  }
  if (code == null) {
    throw new IllegalArgumentException(Errors.format(Errors.Keys.MissingValueForProperty_1,CODE_KEY));
  }
}