...
| Info | ||||
|---|---|---|---|---|
| ||||
Violations can be automatically suppressed across a group of equivalent rules when any of these rules is suppressed at the point of violation. This can be configured by enabling the Automatically suppress violations of equivalent rules setting in the Test Configuration. For details, see Automatically suppress violations of equivalent rules. |
Defining Suppressions in Source Code
...
| Code Block |
|---|
// parasoft-suppress <rule-id>|<rule-category>|ALL "<suppression comment>" |
Examples:
| Code Block |
|---|
int proc1(boolean a, boolean b, int i)
{
if (a | b) // parasoft-suppress CWE "suppress all rules in category CWE"
if (b = a) // parasoft-suppress PB.TYPO.ASI "suppress rule PB.TYPO.ASI"
{
String emptyString1 = ""; // parasoft-suppress CWE-3 "suppress all rules in category CWE with severity level 3 // and lower"
}
else
{
String emptyString2 = ""; // parasoft-suppress SECURITY.WSC.SL BD.PB.VOVR CWE.563.VOVR "suppress multiple rules"
}
return i++; // parasoft-suppress ALL "suppress all rules"
} |
| Anchor | ||||
|---|---|---|---|---|
|
...
Other comments or empty lines are not allowed between the suppression comment and the line that contains the suppressed findings. The only exception is when a list of next line suppressions is specified:
| Code Block |
|---|
// parasoft-suppress-next-line CODSTA.NEA "reason for suppression CODSTA.NEA"
// parasoft-suppress-next-line FORMAT.MCH "reason for suppression FORMAT.MCH"
// parasoft-suppress-next-line JAVADOC "reason for suppression JAVADOC "
... code line ... |
In this case, all suppressions will be applied to the first line after the last suppression comment.
Examples:
| Code Block |
|---|
int proc1(boolean a, boolean b, int i)
{
// parasoft-suppress-next-line CWE "suppress all rules in category CWE"
if (a | b)
// parasoft-suppress-next-line PB.TYPO.ASI "suppress rule PB.TYPO.ASI"
if (b = a)
{
// parasoft-suppress-next-line CWE-3 "suppress all rules in category CWE with severity level 3 and lower"
String emptyString1 = "";
}
// parasoft-suppress-next-line ALL "suppress all rules"
return i++;
} |
| Anchor | ||||
|---|---|---|---|---|
|
...
The 'parasoft-begin-suppress' and 'parasoft-end-suppress' comments must be in separate lines.
Examples:
| Code Block |
|---|
int proc2(boolean a, boolean b, int i)
{
// parasoft-begin-suppress CWE "begin suppress all rules in category CWE"
if (a | b)
if(b = a)
// parasoft-end-suppress CWE "end suppress all rules in category CWE"
{
String emptyString = "";
}
return i++;
}
int proc3(boolean a, boolean b, int i)
{
if (a | b)
// parasoft-begin-suppress PB.TYPO.ASI "begin suppress rule PB.TYPO.ASI"
if(b = a)
// parasoft-end-suppress PB.TYPO.ASI "end suppress rule PB.TYPO.ASI"
{
String emptyString = "";
}
return i++;
}
int proc4(boolean a, boolean b, int i)
{
// parasoft-begin-suppress CWE-3 "begin suppress all rules in category CWE with severity level 3 and lower"
if (a | b)
if(b = a)
{
String emptyString = "";
}
return i++;
// parasoft-end-suppress CWE-3 "end suppress all rules in category CWE with severity level 3 and lower"
}
// parasoft-begin-suppress ALL "begin suppress all rules"
int proc5(boolean a, boolean b, int i)
{
if (a | b)
if(b = a)
{
String emptyString = "";
}
return i++;
}
// parasoft-end-suppress ALL "end suppress all rules" |
To suppress multiple rules in a file, include the following at the beginning/end of the file:
...
- It is a good practice to specify the reason for suppression.
- The following rule patterns are supported:
For example (the following examples are for suppressing violations in a single line):Code Block <rule-id>|<rule-category>|ALL
Suppress rule PB.TYPO.TLS:
Code Block // parasoft-suppress PB.TYPO.TLS
- Suppress all rules in category CODSTA:
Code Block // parasoft-suppress CODSTA
- Suppress all rules in category CODSTA with severity level 4 and lower:
Code Block // parasoft-suppress CODSTA-4
- Suppress multiple rules:
Code Block // parasoft-suppress SECURITY.WSC.SL BD.PB.VOVR CWE.563.VOVR - Suppress all rules:
Code Block // parasoft-suppress ALL
...
Use the following format to add suppression entries to parasoft.suppress files:
| Code Block |
|---|
suppression-begin
file: Account.java (required)
line: 12 (optional)
rule-id: CODSTA-4 (optional)
message: Exact violation message (optional)
reason: Approved (optional)
author: devel (optional)
date: 2020-09-21 (optional)
suppression-end |
Example:
At a minimum, you must specify the source file where the problem was detected. This will suppress all findings reported for the specified file. In the following example, all findings detected in the Account file will be suppressed:
| Code Block |
|---|
suppression-begin
file: Account.java
suppression-end |
You can use the following wildcards and other parameters to specify the file path (this is especially helpful when a non-default location of the parasoft.suppress file is configured in the Additional Settings window):
...
Other attributes are optional and help you fine-tune the suppression. In the following example, all findings that the PB.TYPO.TLS rule detected in the Account file are suppressed, regardless on which code line they occur:
| Code Block |
|---|
suppression-begin
file: Account.java
rule-id: PB.TYPO.TLS
suppression-end |
Notes
- It is a good practice to specify the reason for suppression.
- The
lineattribute should be used with caution as it may invalidate the suppression if the code is moved to another line when the source file is modified. - The following values are supported for the
rule-idattribute:
For example:Code Block <rule-id>|<rule-category>|ALL
Suppress rule PB.TYPO.TLS:
Code Block suppression-begin file: **/autogenerated/* rule-id: PB.TYPO.TLS suppression-end
- Suppress all rules in category CODSTA:
Code Block suppression-begin file: **/autogenerated/* rule-id: CODSTA suppression-end
- Suppress all rules in category CODSTA with severity level 4 and lower:
Code Block suppression-begin file: **/autogenerated/* rule-id: CODSTA-4 suppression-end
- Suppress all rules:
Code Block suppression-begin file: **/autogenerated/* rule-id: ALL suppression-end
- In the
messageattribute, the following wildcards are supported:- ? - Any character
- * - Any sequence of characters
...