Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

checkers.xml: Java KAST configuration

When you run kwcreatechecker, the checkers.xml file is created in the <CHECKER.CODE> directory that you specified with the --code option.

With the exception of the <checkers version> value (1.3), any of the values for the tags listed below can be changed.

By default, the checkers.xml file creates a structure for a single checker. If you want to have several checker groups, checker IDs, and error IDs within the same file, you can manually copy and paste the appropriate tags and edit their values to ensure that the values are unique. See Example: Multiple Java KAST checkers in one file.

The table below provides more information about the elements in the checkers.xml file:

Element Default value Description
<checkers version> 1.3 This version reflects the current Klocwork checker version in use. The value is 1.3 and should NOT be modified.
<categories>   Refers to how an issue is categorized. The highest-level category is by language. See <category name> below.
<category name> Java You can change this value or remove the element to categorize your custom checker differently. Issue categories are visible in the issue Configuration Editor for the server project or the desktop project. The Configuration Editor is where you turn issues on or off for analysis. See Configuring checkers for the integration build analysis.
<error id> <CHECKER.CODE> Reflects the issue code you specified with the --code option of kwcreatechecker. If a checker ID has multiple error IDs, then each error ID should be indicated with its own <error id> tag so that it is appropriately categorized in the Configuration Editor when deployed. See <category name> above for more information about category names. Note: Multibyte characters are not supported in error IDs (checker names), and there's a 255-character limit.
<checkergroup language> Java Indicates that the checker is for Java programs. A single checkers.xml can have multiple checkergroups. This is a manual process. See Example: Multiple Java KAST checkers in one file.
<api> tree_pattern Reflects the checker type you specified with the --type <path or kast> option of kwcreatechecker. The KAST type displays as tree_pattern.
<checker id> <CHECKER.CODE> This ID appears in the analysis results if an issue is detected by this checker. Each checker ID can contain multiple error IDs, each indicated with its own <error id> section. This is a manual process. See Example: Multiple Java KAST checkers in one file.
<libraries> <KAST library name> Contains the list of dynamic libraries the KAST checker depends on. Applies only to checkers using custom functions and created with the --kast-library option.
<library-path> Your_library Specify the path to the dynamic libraries
<error id> <CHECKER.CODE> This ID appears in the analysis results if an issue is detected by this checker. Each checker ID can contain multiple error IDs, each indicated with its own <error id> section. This is a manual process. See Example: Multiple Java KAST checkers in one file.
<enabled> true New checkers are enabled by default, but you can disable them by changing the value to false. The Configuration Editor (available for Klocwork server projects and desktop projects) provides a simple way of enabling or disabling multiple checkers for a project.
<severity> 4 See Issue severity.
<title> "Unexpected semicolon after else" The checker title appears in the Configuration Editor. It is populated with a sample title that should be changed to reflect your custom checker.
<message> "Unexpected semicolon after else" Provide the message you want displayed in the analysis results when an issue is detected by this checker. It is populated with a sample message that should be changed to reflect your custom checker.
<pattern> // IfElseStat [ ElseStat::EmptyStat ] One checker can contain multiple KAST expressions. Each KAST expression must be contained within the <pattern> and </pattern> tags. Don't put the KAST expression into the checkers.xml file until it has been tested and you're ready to build the checker. For more information, see About KAST expressions. If your KAST expression contains a custom function, the plugin_function.xml file should be updated to reflect the custom function in your KAST expression. See plugin_functions.xml: Using custom functionsplugin_functions.xml: Using custom functions and Java custom functions.

Example: Multiple Java KAST checkers in one file

Note: This example does not use custom functions, so it contains no libraries.

A single checkers.xml file can contain multiple checkergroups. Each checkergroup can contain multiple checker IDs, and each checker ID can contain multiple error IDs. To accomplish this, you must copy and paste the appropriate sections (tags) and edit their values to ensure they are unique.

See the example below:

<checkers version="1.3">

    <checkergroup id="JTreePatternCheckers" language="java" api="tree_pattern">

        <checker id="JXPATH.SEMICOL">

            <error id="JXPATH.SEMICOL.THEN" message="unexpected semicolon after then" enabled="false" severity="8" title="JXPATH.SEMICOL.THEN">

                <pattern>

                        // IfStat [ ThenStat::EmptyStat]

                </pattern>

            </error>
            <error id="JXPATH.SEMICOL.ELSE" message="unexpected semicolon after else" enabled="false" severity="8" title="JXPATH.SEMICOL.ELSE">

                <pattern>

                        // IfElseStat [ ElseStat::EmptyStat ]

                </pattern>

            </error>

        </checker>
        <checker id="JXPATH.MISRA.12.4">

            <error id="JXPATH.MISRA.12.4" message="assignment in right operand of boolean operation" enabled="false" severity="8" title="JXPATH.MISRA.12.4">

                <pattern>

                        // ExprBinary [ @Op=OP_ASSIGN

                            @Op=OP_STARASSIGN |
                            @Op=OP_DIVASSIGN
                            @Op=OP_MODASSIGN |
                            @Op=OP_PLUSASSIGN
                            @Op=OP_MINUSASSIGN |
                            @Op=OP_SLASSIGN
                            @Op=OP_SRASSIGN |
                            @Op=OP_BANDASSIGN
                            @Op=OP_BXORASSIGN |
                            @Op=OP_BORASSIGN ]
                            / ancestor::ExprBinary [ @Op=OP_LAND | @Op=OP_LOR ]

                </pattern>
                <pattern>

                        // ExprPrefix [ @Op=OP_INC | @Op=OP_DEC ]

                            / ancestor::ExprBinary [ @Op=OP_LAND | @Op=OP_LOR ]

                </pattern>
                <pattern>

                        // ExprPostfix [ @Op=OP_INC | @Op=OP_DEC ]

                            / ancestor::ExprBinary [ @Op=OP_LAND | @Op=OP_LOR ]

                </pattern>

            </error>

        </checker>

    </checkergroup>

</checkers>

Looking at the example, you can see:

  • there is one checkergroup called JTreePatternCheckers
  • the checkergroup contains two checkers: JXPATH.SEMICOL and JXPATH.MISRA.12.4
  • JXPATH.SEMICOL checker contains two error types, JXPATH.SEMICOL.THEN and JXPATH.SEMICOL.ELSE, each having one KAST expressions contained within the <pattern> tags
  • the JXPATH.MISRA.12.4 checker contains one error with two KAST expressions

Each checker library can contain multiple groups of checkers, each checker group can contain multiple checkers, each checker can define several sub-types (error IDs), and each error ID can contain several KAST expressions.