#21721·checkstyle

SarifLogger: artifactLocation.uri is not properly encoded for file names containing '#', '?', or '%'

Author: vmridulCreated Sep 25, 2026Updated Sep 27, 2026
Labelsapproved

I have read check documentation: https://checkstyle.org/cmdline.html I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

bash
/var/tmp $ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
    "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
    "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="MemberName"/>
  </module>
</module>

/var/tmp $ cat 'Test#1.java'
public class Test {
    private int bad_name;
}

/var/tmp $ java -jar checkstyle-14.1.0-all.jar -c config.xml -f sarif 'Test#1.java'
{
  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
  "version": "2.1.0",
  "runs": [
    {
      "results": [
        {
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "file:/var/tmp/Test#1.java"
                }
              }
            }
          ]
        }
      ]
    }
  ]
}
Checkstyle ends with 1 errors.

Describe what you expect in detail.

In URIs, # denotes a fragment and ? denotes a query string. When Checkstyle outputs file:/var/tmp/Test#1.java, SARIF consumers (e.g., GitHub Code Scanning, VS Code, CI tools) parse /var/tmp/Test as the file path and #1.java as an anchor, failing to find the file on disk. Characters like % or < can also cause URI parsers to throw syntax errors.

Currently, SarifLogger only escapes spaces (%20) and quotes (%22).

File paths in SARIF reports should be percent-encoded where necessary so that the generated URI is valid and decodes to the original file path. This includes characters such as { and } that can occur in filenames but cannot appear literally in a URI path:

  • Test#1.java should produce file:/var/tmp/Test%231.java
  • Test?1.java should produce file:/var/tmp/Test%3F1.java
  • Test%1.java should produce file:/var/tmp/Test%251.java
  • report${message}.java should produce file:/var/tmp/report$%7Bmessage%7D.java