#1337: match .java extension case-insensitively in PmdValidator#1574
Closed
bibonix wants to merge 2 commits intoyegor256:masterfrom
Closed
#1337: match .java extension case-insensitively in PmdValidator#1574bibonix wants to merge 2 commits intoyegor256:masterfrom
bibonix wants to merge 2 commits intoyegor256:masterfrom
Conversation
Reproduces the bug in PmdValidator#getNonExcludedFiles where files with uppercase or mixed-case .java extensions (e.g. .JAVA, .Java) are silently dropped from validation because the regex used to detect Java files is case-sensitive.
PmdValidator#getNonExcludedFiles previously used the case-sensitive regex '^.*\\.java$' to decide whether a file should be passed to PMD. Files with uppercase or mixed-case .java extensions (.JAVA, .Java) were therefore silently skipped on case-insensitive file systems where javac would still happily compile them. Switched to a case-insensitive endsWith check, which is also simpler than the regex it replaces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1337.
Summary
PmdValidator#getNonExcludedFilesskipped files whose.javaextension was not all lowercase, because it filtered with the case-sensitive regex^.*\.java$. On case-insensitive file systems (Windows / default macOS)javachappily compilesFoo.JAVA, but qulice never asked PMD to look at it.name.toLowerCase(Locale.ROOT).endsWith(".java"), which is both case-insensitive and simpler than the regex it replaces.Test plan
acceptsJavaFilesWithUppercaseExtensionandacceptsJavaFilesWithMixedCaseExtensioninPmdValidatorTestthat fail on the old regex and pass with the fix.skipsFilesThatAreNotJavato guard against the obvious regression (non-Java files must still be skipped).mvn -B test) passes after the fix (318 tests, 0 failures).