Program: 25035
Project: 25035
Buggy source:
/** 
 * <p>Compare this function definition with the given ADQL function item.</p> <p> The comparison is done only on the function name and on rough type of the parameters. "Rough type" means here that just the kind of type is tested: numeric, string or geometry. Anyway, the return type is never tested by this function, since such information is usually not part of a function signature. </p> <p>The notion of "greater" and "less" are defined here according to the three following test steps:</p> <ol> <li><b>Name test:</b> if the name of both function are equals, next steps are evaluated, otherwise the standard string comparison (case insensitive) result is returned.</li> <li><b>Parameters test:</b> parameters are compared individually. Each time parameters (at the same position in both functions) are equals the next parameter can be tested, and so on until two parameters are different or the end of the parameters' list is reached. Just the kind of type is used for parameter comparison. Each kind of type is tested in the following order: numeric, string and geometry. When a kind of type is not equal for both parameters, the function exits with the appropriate value (1 if the parameter of this function definition is of the kind of type, -1 otherwise).</li> <li><b>Number of parameters test:</b> in the case where this function definition has N parameters and the given ADQL function has M parameters, and that the L (= min(N,M)) first parameters have the same type in both functions, the value returns by this function will be N-M. Thus, if this function definition has more parameters than the given function, a positive value will be returned. Otherwise a negative value will be returned, or 0 if the number of parameters is the same.</li> </ol>
 * @param fct	ADQL function item to compare with this function definition.
 * @return	A positive value if this function definition is "greater" than the given {@link ADQLFunction}, 0 if they are perfectly matching, or a negative value if this function definition is "less" than the given   {@link ADQLFunction}.
 */
public int compareTo(final ADQLFunction fct){
  if (fct == null)   throw new NullPointerException("String_Node_Str");
  int comp=name.compareToIgnoreCase(fct.getName());
  if (comp == 0) {
    for (int i=0; comp == 0 && i < nbParams && i < fct.getNbParameters(); i++) {
      if (fct.getParameter(i).isNumeric() && fct.getParameter(i).isString() && fct.getParameter(i).isGeometry())       comp=0;
 else       if (params[i].type.isNumeric() == fct.getParameter(i).isNumeric()) {
        if (params[i].type.isString() == fct.getParameter(i).isString()) {
          if (params[i].type.isGeometry() == fct.getParameter(i).isGeometry())           comp=0;
 else           comp=params[i].type.isGeometry() ? 1 : -1;
        }
 else         comp=params[i].type.isString() ? 1 : -1;
      }
 else       comp=params[i].type.isNumeric() ? 1 : -1;
    }
    if (comp == 0 && nbParams != fct.getNbParameters())     comp=nbParams - fct.getNbParameters();
  }
  return comp;
}

Fixed version (ground truth):
/** 
 * <p>Compare this function definition with the given ADQL function item.</p> <p> The comparison is done only on the function name and on rough type of the parameters. "Rough type" means here that just the kind of type is tested: numeric, string or geometry. Anyway, the return type is never tested by this function, since such information is usually not part of a function signature. </p> <p>The notions of "greater" and "less" are defined here according to the three following test steps:</p> <ol> <li><b>Name test:</b> if the name of both function are equals, next steps are evaluated, otherwise the standard string comparison (case insensitive) result is returned.</li> <li><b>Parameters test:</b> parameters are compared individually. Each time parameters (at the same position in both functions) are equals the next parameter can be tested, and so on until two parameters are different or the end of the parameters' list is reached. Just the kind of type is used for parameter comparison. Each kind of type is tested in the following order: numeric, string and geometry. When a kind of type is not equal for both parameters, the function exits with the appropriate value (1 if the parameter of this function definition is of the kind of type, -1 otherwise).</li> <li><b>Number of parameters test:</b> in the case where this function definition has N parameters and the given ADQL function has M parameters, and that the L (= min(N,M)) first parameters have the same type in both functions, the value returns by this function will be N-M. Thus, if this function definition has more parameters than the given function, a positive value will be returned. Otherwise a negative value will be returned, or 0 if the number of parameters is the same.</li> </ol> <p><i><b>Note:</b> If one of the tested types (i.e. parameters types) is unknown, the match should return 0 (i.e. equality). The notion of "unknown" is different in function of the tested item. A   {@link DBType} is unknown if its function{@link DBType#isUnknown()} returns <code>true</code> ; thus, its other functions such as {@link DBType#isNumeric()} willreturn <code>false</code>. On the contrary, an  {@link ADQLOperand} does not have any isUnknown()function. However, when the type of a such is unknown, all its functions isNumeric(), isString() and isGeometry() return <code>true</code>. </i></p>
 * @param fct	ADQL function item to compare with this function definition.
 * @return	A positive value if this function definition is "greater" than the given {@link ADQLFunction}, 0 if they are perfectly matching or one of the tested types (i.e. parameters types) is unknown, or a negative value if this function definition is "less" than the given   {@link ADQLFunction}.
 */
public int compareTo(final ADQLFunction fct){
  if (fct == null)   throw new NullPointerException("String_Node_Str");
  int comp=name.compareToIgnoreCase(fct.getName());
  if (comp == 0) {
    for (int i=0; comp == 0 && i < nbParams && i < fct.getNbParameters(); i++) {
      if (params[i].type.isUnknown() || (fct.getParameter(i).isNumeric() && fct.getParameter(i).isString() && fct.getParameter(i).isGeometry()))       comp=0;
 else       if (params[i].type.isNumeric() == fct.getParameter(i).isNumeric()) {
        if (params[i].type.isString() == fct.getParameter(i).isString()) {
          if (params[i].type.isGeometry() == fct.getParameter(i).isGeometry())           comp=0;
 else           comp=params[i].type.isGeometry() ? 1 : -1;
        }
 else         comp=params[i].type.isString() ? 1 : -1;
      }
 else       comp=params[i].type.isNumeric() ? 1 : -1;
    }
    if (comp == 0 && nbParams != fct.getNbParameters())     comp=nbParams - fct.getNbParameters();
  }
  return comp;
}