The Autofix plugin leverages LLM tools to fix code violations in your Java projects running within automated CI/CD pipelines, based on a generated analysis report. Jtest identifies violations, uses LLM integration to propose fixes for those violations, and verifies each proposed fix to ensure that all issues are fully resolved and no new problems are introduced. Successful fixes result in automatically created commits in the working branch of your project source control repository, enabling manual review and approval before merging.
The Jtest Autofix Python script is located in <INSTALL_DIR>/integration/aider.
Prerequisites
The following are required to use this functionality:
- Python 3.10-3.12
- A version control system
- Your secret LLM provider API key
This feature depends on LLMs, which may produce inaccurate information
Jtest Autofix Configuration
Preparing a Virtual Environment
We strongly recommend running the JtestAutoFix.py script inside a Python virtual environment to isolate it from your system-wide Python installation and prevent dependency conflicts.
Follow these steps to set up your virtual environment:
Windows
- Create a virtual environment:
python -m venv venv
- Enter the virtual environment:
CALL venv\Scripts\activate.bat
- Install the required dependencies:
python -m pip install --upgrade pip pip install -r requirements.txt
Linux/Unix
- Create a virtual environment:
python -m venv venv
- Enter the virtual environment:
source venv/bin/activate
- Install required dependencies:
python -m pip install --upgrade pip pip install -r requirements.txt
Autofix Configuration Options
The JtestAutoFix.py script can be configured using environment variables or command-line arguments. Command-line arguments take precedence over environment variables when both are specified.
Below is the complete reference for all available configuration options:
| Option | Required | CLI Argument | Environment Variable | Default Value | Description |
|---|---|---|---|---|---|
| LLM API Key | Yes | N/A | %PROVIDER%_API_KEY=<KEY> | - | Your secret LLM provider API key required by Aider. Replace %PROVIDER% with the provider of your choice. Learn more about providers and variables. |
| Data file | Yes | --data DATA_FILE_PATH | N/A | - | Path to the Jtest .data.json file. It must match the project used for the baseline analysis report. |
| Baseline Report | Yes | --report XML_REPORT_PATH | REPORT=<XML_REPORT_PATH> | - | Path to the Jtest XML report containing violations to be fixed. |
| Tool Home | No | --tool-home JTEST_HOME | TOOL_HOME=<JTEST_HOME> | Jtest directory | Path to the Jtest installation directory. By default, it is set to the "../.." directory where the script is located. |
| Fix Limit | No | --fix-limit COUNT | FIX_LIMIT=<COUNT> | 0 (no limit) | Maximum number of violation fix attempts per run. |
| Max Attempts | No | --max-attempts MAX_ATTEMPTS | N/A | 3 | Maximum retry attempts per violation before stopping. |
| Model Name | No | N/A | MODEL_NAME=MODEL | gpt-4o-mini | AI model for fixing violations (e.g., gpt-4, gpt-4o, claude-3-sonnet). Use aider --list-models <fragment> to see the available models. |
| Weak Model Name | No | N/A | WEAK_MODEL_NAME=MODEL | - | Lightweight model for auxiliary tasks, such as commit message generation. When not specified, it defaults to the specified model name (MODEL_NAME). |
| Verification Command | No | --verification-command COMMAND | N/A | - | Command to verify code integrity after each fix (e.g., "mvn compile" or "./gradlew assemble"). Success is determined by exit code (0 = success). |
| No Source Control | No | --allow-no-source-control | N/A | Disabled | Bypass source control warnings. Use with caution - changes will be made without version control and cannot be reverted. |
| Help | No | -h or --help | N/A | N/A | Display help information for the JtestAutoFix.py script. |
Configuring the Environment
You can use the provided .env.template file as a starting point to create your own .env file with the necessary environment variables.
Running Autofix
Before running the Autofix script, we recommend creating a dedicated branch for the automated fixes. This allows you to review and test all changes before merging them into your main branch.
Basic Usage for a Gradle project
Windows
- Set your API key:
SET OPENAI_API_KEY=your_secret_open_ai_key
- Execute Autofix with the recommended settings:
python JtestAutoFix.py --report "<PROJECT_PATH>/build/jtest/report.xml" --max-attempts 3 --data "<PROJECT_PATH>/build/jtest/jtest.data.json" --tool-home "C:\Program Files\Parasoft\Jtest\2025.2"
Linux/Unix
- Set your API key:
export OPENAI_API_KEY=your_secret_open_ai_key
- Execute Autofix with the recommended settings:
python3 JtestAutoFix.py --report "<PROJECT_PATH>/build/jtest/report.xml" --max-attempts 3 --data "<PROJECT_PATH>/build/jtest/jtest.data.json" --tool-home "/opt/parasoft/jtest/2025.2"
Advanced Usage Examples
Windows with the Verification Command
- Set the environment variables:
SET OPENAI_API_KEY=your_secret_open_ai_key SET MODEL_NAME=gpt-4.1 SET WEAK_MODEL_NAME=gpt-4o-mini
- Execute Autofix with build verification:
python JtestAutoFix.py --report "C:\projects\myapp\build\jtest\report.xml" --data "C:\projects\myapp\build\jtest\jtest.data.json" --tool-home "C:\Program Files\Parasoft\Jtest\2025.2" --verification-command "gradle build" --fix-limit 10 --max-attempts 2
Linux/Unix with the Verification Command
- Set the environment variables:
export OPENAI_API_KEY=your_secret_open_ai_key export MODEL_NAME=gpt-4.1 export WEAK_MODEL_NAME=gpt-4o-mini
- Execute Autofix with build verification:
python JtestAutoFix.py --report "/home/user/projects/myapp/build/jtest/report.xml" --data "/home/user/projects/myapp/build/jtest/jtest.data.json" --tool-home "/opt/parasoft/jtest/2025.2" --verification-command "./gradlew build" --fix-limit 10 --max-attempts 2
To ensure accurate results and efficient use of the Autofix plugin, follow these best practices:
Generate a new baseline after each Autofix session: Code changes made during the autofix process can alter file line numbers and structure, making the violation locations in your original report.xml obsolete. Regenerate your baseline report to ensure it accurately reflects your updated codebase.
Fix history tracking: The script creates data files in the .cliAutoFix folder to track fix attempts and outcomes in *.history.yaml files.
Preserve history: To avoid re-attempting the same violations:
- Preserve the
.cliAutoFixfolder and its*.history.yamlfiles between runs. - Alternatively, ensure all attempted violations are either fixed or suppressed before the next run.
Reviewing Results
After each successful fix, the Autofix script creates a commit in your repository. Since AI-generated code may contain errors or suboptimal solutions, it is crucial to review all changes carefully.
Follow these best practices when reviewing AI-generated fixes:
- Read the commit messages - Understand what changes were made and why.
- Test the changes - Ensure the fix resolves the violation without introducing new issues.
- Check the code quality - Verify that the fix follows your team's coding standards.
- Apply incremental fixes - For minor issues in otherwise good fixes, create separate commits with manual corrections.
- Revert when necessary - If a fix is fundamentally wrong, revert the entire commit.
- Use a branching strategy - Work on a feature branch and merge after review, or cherry-pick verified commits.
Troubleshooting
If you encounter any issues while running the script, ensure that:
- All dependencies are correctly installed
- Environment variables are properly configured
- All required CLI parameters are properly passed
- Linux/Unix only: Ensure that Python 3.10+ is installed and accessible via the
python3orpythoncommands. - Linux/Unix only: Check the file permissions for the script and data files.