refactor: address code smells and fix Windows build flakiness#758
Open
Anik1459 wants to merge 4 commits into
Open
refactor: address code smells and fix Windows build flakiness#758Anik1459 wants to merge 4 commits into
Anik1459 wants to merge 4 commits into
Conversation
… in WordUtils WordUtils.capitalize() and WordUtils.uncapitalize() shared an identical 28-line tokenisation loop differing only by a single function call (Character::toTitleCase vs Character::toLowerCase). DRY violation: any future change must be applied in two places. Extracted to private applyWordCaseTransform(String, char[], IntUnaryOperator). Both public methods now delegate with a method reference. No API change. All 37 WordUtilsTest cases pass.
Member
|
Hello @Anik1459 Please only include changes for what you see as "Windows build flakiness" and remove the rest. Where is this flakiness demonstarted? |
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.
Summary
This PR addresses four code quality issues identified through manual inspection
and static analysis of the codebase.
Changes
1. Fix cross-drive test failure on Windows (FileStringLookupTest)
testFenceRelativeParentTraversalused@TempDirwhich JUnit resolves tothe OS temp directory. On Windows, this may be on a different drive (e.g.
C:\)than the project (e.g.
E:\), causingPath.relativize()to throwIllegalArgumentException— unrelated to the code under test.Fixed by using
target/tempDirandtarget/fence, which are guaranteed to beon the same drive as the project. The relative traversal path (
../) is stillcorrectly generated and rejected by the fencing lookup as intended.
2. Improve exception diagnostics in ExtendedMessageFormat
Two
IllegalArgumentExceptions inapplyPattern()used the generic message"The validated expression is false"— a leftover from an inlinedValidate.isTrue()call. This provides no diagnostic value in logs or debuggers.Replaced with specific messages that include the actual vs expected format count.
3. Name magic constants in JaroWinklerSimilarity
The algorithm-specific literals
4(max prefix length) and0.7d(Winklerthreshold) were used inline with no explanation. Extracted to named constants
MAX_PREFIX_LENGTHandDEFAULT_WINKLER_THRESHOLD. No behavioural change.4. Eliminate duplicated loop in WordUtils (Extract Method)
capitalize()anduncapitalize()shared an identical 28-line tokenisationloop differing only by one function call (
Character::toTitleCasevsCharacter::toLowerCase). Extracted to a privateapplyWordCaseTransform()helper that accepts an
IntUnaryOperator. Both public methods now delegatewith a single line. No public API change.
Testing
mvn clean test— all tests pass (0 failures, 0 errors)Notes
StringSubstitutor.substitute()(~140 lines, cyclomatic complexity ~25) wasidentified as a Long Method smell but deliberately excluded. Refactoring that
performance-critical inner loop carries a high regression risk not appropriate
for this change set.