Skip to content

CommonUtil.getFileExtension includes parent-directory dots in the extension #21501

Closed

Description

@ishu7w

This concerns the public filename utility rather than a Check module, so the reproduction below calls the utility directly. I have not demonstrated a normal Checkstyle CLI failure.

Reproduction

Examined revision: 12c899d48d666c421989139de67c2e84cc6667ce (14.1.1-SNAPSHOT), macOS, Java 21. The same implementation is still present on current master.

CommonUtil.getFileExtension("config.d/filename"); // actual: "d/filename"
CommonUtil.getFileExtension("./filename");        // actual: "/filename"
CommonUtil.getFileExtension("../filename");       // actual: "/filename"

Expected: an empty string in each case because the final filename has no extension. config.d/filename.properties should continue returning properties.

Cause and proposed change

getFileExtension searches the entire path for the final dot. Extracting the final filename before looking for a dot would make it consistent with the neighboring getFileNameWithoutExtension helper:

final String fileName = Path.of(fileNameWithExtension).toFile().getName();

The current internal caller, TranslationCheck, already passes File.getName(), so its normal behavior is unaffected. Please confirm whether accepting paths in this public utility is intended; if the contract is deliberately restricted to bare filenames, documentation may be more appropriate.

Local validation of the proposed patch

  • Added two regression tests covering dotted parent directories and current/parent-relative paths, plus preservation of real extensions.
  • Before the production change: CommonUtilTest ran 50 tests with 2 failures, both new regression tests.
  • After: mvn test -Dtest=CommonUtilTest,TranslationCheckTest passed all 74 tests.
  • Java 21 mvn clean verify: BUILD SUCCESS; 6,789 unit/example tests (2 skipped) and 1,347 integration tests, no failures or errors.

I have a focused local patch ready and will wait for issue approval before opening a PR. Codex assisted with investigation, patch preparation, and local validation.

Activity

  1. romani commented on Sep 8, 2026

    @romani
    Member

    Please send PR, let me see more details at implementation place

  2. ishu7w commented on Sep 8, 2026

    @ishu7w
    ContributorAuthor

    Thanks, @romani. Submitted the implementation in #21518 for review. It includes regression tests for dotted parent directories and relative paths. Java 21 mvn clean verify passed on the updated branch.

  3. added a commit that references this issue on Sep 9, 2026
  4. added this to the 14.1.1 milestone on Sep 9, 2026
  5. romani commented on Sep 9, 2026

    @romani
    Member

    fix is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions