Skip to content

File Path Substring Logic (Potential Bug) #1333

@DeHopen

Description

@DeHopen

@yegor256

In both CheckstyleValidator.getNonExcludedFiles and CheckstyleListener.addError, the code does:

final String name = file.getPath().substring(this.env.basedir().toString().length());

Problem: If the file path does not start with the base directory path, this will result in a substring that is not a valid relative path, or even an exception (if the file is outside the base directory).
Consequence: This could cause incorrect exclusion logic or even runtime exceptions.

Fix: Use a robust method to get the relative path, such as Path relativize from java.nio.file.Path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions