Skip to content

Java Codeanalyzer fails when paths have spaces in them #144

@timrbula

Description

@timrbula

Describe the bug

Java codeanalyzer fails when project or CLDK installation path has a space in it.

To Reproduce
Steps to reproduce the behavior:

  1. Run Java codeanalyzer.py against Java project with space in path e.g. /Users/user/My Projects/java-project
    OR
  2. Install CLDK in a location with a space in the path e.g. /Users/user/Library/Application Support/python3.12/site-packages/cldk

Expected behavior
The code analysis should be performed without failing

Logs

See in the log that the path to the codeanalyzer-2.3.5.jar is split into two args in the command list.

cldk.utils.exceptions.exceptions.CodeanalyzerExecutionException: Command '['java', '-jar', '/Users/timrbula/Library/Application', 'Support/uv/tools/aster/lib/python3.12/site-packages/cldk/analysis/java/codeanalyzer/jar/codeanalyzer-2.3.5.jar', '-i', '/Users/timrbula/Workspaces/tmp/commons-cli', '--analysis-level=1', '-o', '/Users/timrbula/Workspaces/tmp/commons-cli/output/commons-cli', '-v']' returned non-zero exit status 1.

Additional context

File: cldk/analysis/java/codeanalyzer/codeanalyzer.py

Potential fixes:

Quote the path values in the f-string e.g. codeanalyzer_args = codeanalyzer_exec + shlex.split(f"-i '{Path(self.project_dir)}' --analysis-level={analysis_level} -o '{Path(self.analysis_json_path)}' -v")

Wrap the path in a shlex.quote call e.g. shlex.split(f"java -jar {shlex.quote(str(codeanalyzer_jar_file))}")

OS: macOS 15.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions