Skip to content

Stop ExtendedMessageFormat seekNonWs reading past the pattern end#1740

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

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

Conversation

@dxbjavid

@dxbjavid dxbjavid commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Port of apache/commons-text#759 to the equivalent org.apache.commons.lang3.text.ExtendedMessageFormat.

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, alongside the JRE sanity checks you added post-merge on the commons-text side.

@garydgregory garydgregory merged commit 2011ce3 into apache:master Jul 3, 2026
20 of 21 checks passed
@garydgregory

Copy link
Copy Markdown
Member

Hello @dxbjavid , merged 🚀 TY!

@garydgregory garydgregory changed the title stop ExtendedMessageFormat seekNonWs reading past the pattern end Stop ExtendedMessageFormat seekNonWs reading past the pattern end Jul 3, 2026
@dxbjavid

dxbjavid commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @garydgregory for the review and merge. I appreciate your guidance in porting the fix from Commons Text to Commons Lang. Glad to contribute, and thanks again!

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