CodeQL 文档

虚假 Javadoc @param 标签

ID: java/unknown-javadoc-parameter
Kind: problem
Security severity: 
Severity: recommendation
Precision: very-high
Tags:
   - maintainability
Query suites:
   - java-security-and-quality.qls

单击以在 CodeQL 仓库中查看查询

公共方法、构造函数和泛型类的 Javadoc 注释应使用 @param 标签来描述可用的参数和类型参数。如果注释包含任何空、不正确或过时的参数名,这将使文档更难阅读。

建议

方法、构造函数或泛型类的 Javadoc 注释应始终使用与实际参数或类型参数名匹配的非空 @param 值。

示例

以下示例显示了使用 @param 标签的良好和不良 Javadoc 注释。

/**
 * BAD: The following param tag is empty.
 *
 * @param   
 */ 
public void emptyParamTag(int p){ ... }


/**
 * BAD: The following param tag has a misspelled value.
 *
 * @param prameter The parameter's value.
 */ 
public void typo(int parameter){ ... }


/**
 * BAD: The following param tag appears to be outdated
 * since the method does not take any parameters.
 *
 * @param sign The number's sign.
 */ 
public void outdated(){ ... }


/**
 * BAD: The following param tag uses html within the tag value.
 *
 * @param <code>ordinate</code> The value of the y coordinate.
 */ 
public void html(int ordinate){ ... }


/**
 * BAD: Invalid syntax for type parameter.
 *
 * @param T The type of the parameter.
 * @param parameter The parameter value.
 */ 
public <T> void parameterized(T parameter){ ... }

/**
 * BAD: The following param tag refers to a non-existent type parameter.
 * 
 * @param <X> The type of the elements.
 */
class Generic<T> { ... }

/**
 * GOOD: A proper Javadoc comment.
 *
 * This method calculates the absolute value of a given number.
 *
 * @param <T> The number's type.
 * @param x The number to calculate the absolute value of.
 * @return The absolute value of <code>x</code>.
 */ 
public <T extends Number> T abs(T x){ ... }

参考资料

  • ©GitHub, Inc.
  • 条款
  • 隐私