Skip to content

Issue #21501: Fix file extensions for paths with dotted directories - #21518

Merged
romani merged 1 commit into
checkstyle:masterfrom
ishu7w:codex/fix-extension-dotted-directory
Sep 9, 2026
Merged

romani merged 1 commit into
checkstyle:masterfrom
ishu7w:codex/fix-extension-dotted-directory

Conversation

@ishu7w

@ishu7w ishu7w commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Issue: #21501

Submitted following romani's request to review the implementation in a PR.

CommonUtil.getFileExtension("config.d/filename") currently returns d/filename, even though the final filename has no extension. Extract the final filename before searching for its last dot, using the same approach as getFileNameWithoutExtension.

Add regression tests for dotted parent directories and current/parent-relative paths, including preservation of a real .properties extension. This addresses the public utility; the existing TranslationCheck caller already supplies a bare filename.

Validation:

  • Before the production change, both new regression tests failed.
  • After the change, all 74 tests in CommonUtilTest and TranslationCheckTest passed.
  • After rebasing onto d89b173, Java 21 mvn -B -ntp clean verify passed: 6,790 unit/example tests (2 skipped), 1,349 integration tests, and all configured quality checks; no failures or errors.

Codex assisted with investigation, implementation, and validation.

@ishu7w

ishu7w commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Hi @romani, I opened this PR following your request in #21501 (comment). The Check PR Description workflow is failing because #21501 does not yet have the approved label: https://github.com/checkstyle/checkstyle/actions/runs/34238961004. Could you please review the implementation and, if you approve the issue, add the label and rerun the check? Thanks.

@arturict arturict left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked this on linux: both new tests fail on master, config.d/filename gives d/filename and ../filename gives /filename, and they pass with the change. it also lines up with what getFileNameWithoutExtension has been doing all along.

*/
public static String getFileExtension(String fileNameWithExtension) {
final String fileName = Path.of(fileNameWithExtension).toString();
final String fileName = Path.of(fileNameWithExtension).toFile().getName();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code might be 20 years old.
and I think modern jdk already should have method for get file extension.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot

@romani
romani merged commit 1a994ba into checkstyle:master Sep 9, 2026
131 of 133 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants