Detect Method Parameter (detectMethodParameter)

<detectMethodParameter> Element

The detectMethodParameter rule is used for detecting method parameters in Java classes.

Table 1. <detectMethodParameter> Element Attributes
Attribute Name Type Required Description
name String Yes

The method name.

owners String Yes

The fully qualified class name of the class where the method is defined. If providing multiple, use a comma separated list.

returnType String No

The fully qualified class name of the return type.

arguments String No

The fully qualified class names or primitives of the method arguments. If specifying multiple, use a comma separated list. Specify an empty string to flag the method with no parameters. If not specified, flag all method signatures.

flagCatchExceptions String No

The fully qualified class names of the exceptions. If specifying multiple, use a comma separated list. Flag calls to the method if it is inside a try and catch block for any of the specified exceptions.

flagUnhandledExceptions String No

Fully qualified class names of the exceptions. If specifying multiple, use a comma separated list. Flag calls to the method if none of the specified exceptions are caught or thrown by the invoking method.

flagOnce Boolean No

Indicates whether to flag once per archive. Defaults to false.

flagOncePerFile Boolean No

Indicates whether to flag once per file. Defaults to false.

hideResult Boolean No

Indicates whether results flagged by this rule should be hidden in the report. This attribute only hides results when used with rules under the <and> or <or> tags. Defaults to false.

Child Elements (One or more)

<argument> Element - required, can be multiple

Table 2. <argument> Element Attributes
Attribute Name Type Required Description
position Integer Yes

The position of the argument, starting with 0.

flagVariable Boolean No

Indicates whether or not to flag a variable for this argument position. Defaults to false.

flagStringLiteral Regex No

Flag if this string literal value is provided for this method parameter.

flagVariableValue Regex No

Flag if this variable value is provided for this method parameter.

flagType String No

A fully qualified class name. Use this when you need to flag a specific type, but the method argument is more generic, such as java.lang.Object.

flagTypeLiteral Boolean No

Indicates whether to match on a type literal, such as someClass.class. Defaults to false.

For example, to detect a createSession method on the javax.jms.Connection class with an int parameter that is specified with a string literal or variable value of 0, specify:


<detectMethodParameter name="createSession" arguments="int" owners="javax.jms.Connection">
    <argument position="0" flagVariable="true" flagVariableValue="0" flagStringLiteral="0"/>
</detectMethodParameter>