Skip to content

Stop ExtendedMessageFormat seekNonWs reading past the pattern end#759

Merged
garydgregory merged 1 commit into
apache:masterfrom
dxbjavid:seeknonws-bounds
Jul 2, 2026
Merged

Stop ExtendedMessageFormat seekNonWs reading past the pattern end#759
garydgregory merged 1 commit into
apache:masterfrom
dxbjavid:seeknonws-bounds

Conversation

@dxbjavid

@dxbjavid dxbjavid commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

The registry-based ExtendedMessageFormat constructor parses its pattern with seekNonWs, which asks the split matcher about the character at the current parse index without first checking it is still inside the buffer. A truncated format element such as {, {0, or trailing text like {0}extra{ leaves the parse position at the end of the pattern, so the matcher reads one past the char array and the constructor throws ArrayIndexOutOfBoundsException rather than the documented IllegalArgumentException that the plain constructor already gives for the same input. This bounds the seek to the pattern length so those patterns report the usual unterminated-format-element error; a regression test covers the three shapes above.

@garydgregory garydgregory changed the title stop ExtendedMessageFormat seekNonWs reading past the pattern end Stop ExtendedMessageFormat seekNonWs reading past the pattern end Jul 2, 2026
@garydgregory garydgregory merged commit 1f3b162 into apache:master Jul 2, 2026
10 checks passed
@garydgregory

Copy link
Copy Markdown
Member

@dxbjavid
Thank you for the PR, merged 🚀 Would you please port to Apache Commons Lang? See the assertions I added in 742fac0 post merge.

@dxbjavid

dxbjavid commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

sounds good, i'll port it across to commons-lang. its text.ExtendedMessageFormat carries the same seekNonWs helper, so the bounds fix and the truncated-element tests should move over cleanly, and i'll fold in the JRE sanity checks you added. will raise that separately.

@dxbjavid

dxbjavid commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

ported to commons-lang in apache/commons-lang#1740 - same seekNonWs bounds fix, the three truncated shapes and the JRE sanity checks all carried over.

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