Remove duplicated surrogate-pair start adjustment in StringUtils.mid() - #2
Draft
java-dependency-upgrade-fixer[bot] wants to merge 1 commit into
Draft
Conversation
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.
Context
Mirrors upstream apache/commons-lang PR apache#1776 (StringUtils.left/right/mid/overlay stay off surrogate-pair boundaries), as re-proposed at head 164ab3a against base e66ad3d.
Change
In
StringUtils.mid(String, int, int), the surrogate-pair-safestartcomputation (int start = pos; if (splitsSurrogatePair(str, start)) start++;) was duplicated verbatim in both the early-return branch and the general branch, even though it only depends onstrandpos, which are identical in both branches. This companion hoists the computation once above the branch; theendadjustment remains only whereendis computed.Why it's safe
testMidSurrogatePairsstyle fuzzing over every pos/len combination for a string mixing surrogate pairs and plain chars) pass identically before and after: 194 focused tests, 0 failures, 0 errors, 1 pre-existing skip.What was evaluated and not changed
left(),right(), andoverlay()already contain minimal, non-duplicated logic; no safe simplification was found.splitsSurrogatePairadjustment pattern acrossleft/right/mid/overlaywas considered and rejected: the same inline pattern already exists in unrelated pre-existing methods (abbreviate,abbreviateMiddle,chop,substring) outside this PR's changed scope, so a shared helper would either create inconsistency with those methods or require an unrelated, unbounded refactor.Limitations
This is a bounded 4-line cleanup inside one already-changed method. It does not add new test coverage beyond what the original PR already provides, since the existing tests already exhaustively fuzz
mid()across pos/len space and are sufficient to lock this method's behavior.Generated by JAIPilot Cloud for #1 from Anthropic session
sesn_01WcsYEJ69Kx3ubEWJ5bn7Jx.