Skip to content

DateUtils: fix error handling code path in the parseLocalDateTime12 methods - #7957

Open
c247t wants to merge 2 commits into
alibaba:mainfrom
c247t:dateutils-error-handling-fix
Open

c247t wants to merge 2 commits into
alibaba:mainfrom
c247t:dateutils-error-handling-fix

Conversation

@c247t

@c247t c247t commented Nov 17, 2026

Copy link
Copy Markdown

Purpose

Avoid StringIndexOutOfBounds, ensure DateTimeParseException with proper message

Since we are already in the error handling path, the issue being fixed does not break parsing of any valid input. Still, the out-of-bounds access is confusing at first.

Change Summary

Fix the out-of-bounds length arguments to String constructors in the parseLocalDateTime12 method family of DateUtils

The mistake was as simple as it was understandable: the argument passed should be the length to be included in the new String, not the end position inside the byte[] / char[] input. Surrounding calls to the digit* method family of IOUtils take an offset as their second argument, making the addition seem valid at a glance.

Not adding the offset to the constant length fixes the issue.

Validation

  • The fix was made in a TDD fashion: add failing test first, then fix the offending code.
  • Care was taken to make commit message resemble the usual patterns and the Conventional Commits ruleset.
  • No preexisting test or other functionality is affected by this change.

@CLAassistant

CLAassistant commented Nov 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

2 participants