Program: 91943
Project: 91943
Buggy source:
/** 
 * Parses the given symbol. This method is similar to   {@link Unit#valueOf(CharSequence)}, but hands especially a few symbols found in WKT parsing or in XML files. The list of symbols handled especially is implementation-dependent and may change in future SIS versions. <div class="section">Parsing authority codes</div> As a special case, if the given   {@code uom} arguments is of the form {@code "EPSG:####"}or   {@code "urn:ogc:def:uom:EPSG:####"} (ignoring case and whitespaces), then {@code "####"}is parsed as an integer and forwarded to the   {@link #valueOfEPSG(int)} method.<div class="section">NetCDF unit symbols</div> The attributes in NetCDF files often merge the axis direction with the angular unit, as in  {@code "degrees_east"} or {@code "degrees_north"}. This   {@code valueOf} methodignores those suffixes and unconditionally returns  {@link NonSI#DEGREE_ANGLE} for allaxis directions. In particular, the units for  {@code "degrees_west"} and {@code "degrees_east"}do <strong>not</strong> have opposite sign. It is caller responsibility to handle the direction of axes associated to NetCDF units.
 * @param uom The symbol to parse, or {@code null}.
 * @return The parsed symbol, or {@code null} if {@code uom} was null.
 * @throws IllegalArgumentException if the given symbol can not be parsed.
 */
public static Unit<?> valueOf(String uom) throws IllegalArgumentException {
  if (uom == null) {
    return null;
  }
  uom=trimWhitespaces(CharSequences.toASCII(uom)).toString();
  final int length=uom.length();
  if (isURI(uom)) {
    String code=DefinitionURI.codeOf("String_Node_Str",Constants.EPSG,uom);
    if (code != null && code != uom)     try {
      return valueOfEPSG(Integer.parseInt(code));
    }
 catch (    NumberFormatException e) {
      throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,"String_Node_Str",uom),e);
    }
    code=XPaths.xpointer("String_Node_Str",uom);
    if (code != null) {
      uom=code;
    }
  }
  if (uom.regionMatches(true,0,"String_Node_Str",0,3)) {
switch (length) {
case 3:
      return NonSI.DEGREE_ANGLE;
case 4:
{
      if (uom.charAt(3) == 'K') {
        return SI.KELVIN;
      }
      break;
    }
}
String prefix=uom;
boolean isTemperature=false;
final int s=Math.max(uom.lastIndexOf(' '),uom.lastIndexOf('_'));
if (s >= 1) {
  final String suffix=(String)trimWhitespaces(uom,s + 1,length);
  if (ArraysExt.containsIgnoreCase(CARDINAL_DIRECTIONS,suffix) || (isTemperature=isCelsius(suffix))) {
    prefix=(String)trimWhitespaces(uom,0,s);
  }
}
if (equalsIgnorePlural(prefix,"String_Node_Str")) {
  return isTemperature ? SI.CELSIUS : NonSI.DEGREE_ANGLE;
}
}
 else {
if (uom.equals("String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.DEGREE_ANGLE;
if (uom.equalsIgnoreCase("String_Node_Str")) return NonSI.SECOND_ANGLE;
if (uom.equalsIgnoreCase("String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return SI.RADIAN;
if (equalsIgnorePlural(uom,"String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return SI.KILOMETRE;
if (equalsIgnorePlural(uom,"String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return SI.METRE;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.WEEK;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.DAY;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.HOUR;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.MINUTE;
if (equalsIgnorePlural(uom,"String_Node_Str")) return SI.SECOND;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.PIXEL;
if (isCelsius(uom)) return SI.CELSIUS;
if (uom.isEmpty()) return Unit.ONE;
if (uom.equalsIgnoreCase("String_Node_Str")) return PPM;
if (uom.equalsIgnoreCase("String_Node_Str")) return PSU;
if (uom.equalsIgnoreCase("String_Node_Str")) return SIGMA;
}
final Unit<?> unit;
try {
unit=Unit.valueOf(uom);
}
 catch (IllegalArgumentException e) {
throw Exceptions.setMessage(e,Errors.format(Errors.Keys.IllegalArgumentValue_2,"String_Node_Str",uom),true);
}
if (unit.isCompatible(SI.HERTZ) && !uom.equals("String_Node_Str")) {
return SI.HERTZ;
}
return UnitsMap.canonicalize(unit);
}

Fixed version (ground truth):
/** 
 * Parses the given symbol. This method is similar to   {@link Unit#valueOf(CharSequence)}, but hands especially a few symbols found in WKT parsing or in XML files. The list of symbols handled especially is implementation-dependent and may change in future SIS versions. <div class="section">Parsing authority codes</div> As a special case, if the given   {@code uom} arguments is of the form {@code "EPSG:####"}or   {@code "urn:ogc:def:uom:EPSG:####"} (ignoring case and whitespaces), then {@code "####"}is parsed as an integer and forwarded to the   {@link #valueOfEPSG(int)} method.<div class="section">NetCDF unit symbols</div> The attributes in NetCDF files often merge the axis direction with the angular unit, as in  {@code "degrees_east"} or {@code "degrees_north"}. This   {@code valueOf} methodignores those suffixes and unconditionally returns  {@link NonSI#DEGREE_ANGLE} for allaxis directions. In particular, the units for  {@code "degrees_west"} and {@code "degrees_east"}do <strong>not</strong> have opposite sign. It is caller responsibility to handle the direction of axes associated to NetCDF units.
 * @param uom The symbol to parse, or {@code null}.
 * @return The parsed symbol, or {@code null} if {@code uom} was null.
 * @throws IllegalArgumentException if the given symbol can not be parsed.
 */
public static Unit<?> valueOf(String uom) throws IllegalArgumentException {
  if (uom == null) {
    return null;
  }
  uom=trimWhitespaces(CharSequences.toASCII(uom)).toString();
  final int length=uom.length();
  if (isURI(uom)) {
    String code=DefinitionURI.codeOf("String_Node_Str",Constants.EPSG,uom);
    if (code != null && code != uom)     try {
      return valueOfEPSG(Integer.parseInt(code));
    }
 catch (    NumberFormatException e) {
      throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,"String_Node_Str",uom),e);
    }
    code=XPaths.xpointer("String_Node_Str",uom);
    if (code != null) {
      uom=code;
    }
  }
  if (uom.regionMatches(true,0,"String_Node_Str",0,3)) {
switch (length) {
case 3:
      return NonSI.DEGREE_ANGLE;
case 4:
{
      if (uom.charAt(3) == 'K') {
        return SI.KELVIN;
      }
      break;
    }
}
String prefix=uom;
boolean isTemperature=false;
final int s=Math.max(uom.lastIndexOf(' '),uom.lastIndexOf('_'));
if (s >= 1) {
  final String suffix=(String)trimWhitespaces(uom,s + 1,length);
  if (ArraysExt.containsIgnoreCase(CARDINAL_DIRECTIONS,suffix) || (isTemperature=isCelsius(suffix))) {
    prefix=(String)trimWhitespaces(uom,0,s);
  }
}
if (equalsIgnorePlural(prefix,"String_Node_Str")) {
  return isTemperature ? SI.CELSIUS : NonSI.DEGREE_ANGLE;
}
}
 else {
if (uom.equals("String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.DEGREE_ANGLE;
if (uom.equalsIgnoreCase("String_Node_Str")) return NonSI.SECOND_ANGLE;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.GRADE;
if (uom.equalsIgnoreCase("String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return SI.RADIAN;
if (equalsIgnorePlural(uom,"String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return SI.KILOMETRE;
if (equalsIgnorePlural(uom,"String_Node_Str") || equalsIgnorePlural(uom,"String_Node_Str")) return SI.METRE;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.WEEK;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.DAY;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.HOUR;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.MINUTE;
if (equalsIgnorePlural(uom,"String_Node_Str")) return SI.SECOND;
if (equalsIgnorePlural(uom,"String_Node_Str")) return NonSI.PIXEL;
if (isCelsius(uom)) return SI.CELSIUS;
if (uom.isEmpty()) return Unit.ONE;
if (uom.equalsIgnoreCase("String_Node_Str")) return PPM;
if (uom.equalsIgnoreCase("String_Node_Str")) return PSU;
if (uom.equalsIgnoreCase("String_Node_Str")) return SIGMA;
}
final Unit<?> unit;
try {
unit=Unit.valueOf(uom);
}
 catch (IllegalArgumentException e) {
throw Exceptions.setMessage(e,Errors.format(Errors.Keys.IllegalArgumentValue_2,"String_Node_Str",uom),true);
}
if (unit.isCompatible(SI.HERTZ) && !uom.equals("String_Node_Str")) {
return SI.HERTZ;
}
return UnitsMap.canonicalize(unit);
}