Skip to content

throw IllegalArgumentException for trailing whitespace in ExtendedMessageFormat argument index#750

Open
dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:argument-index-trailing-ws
Open

throw IllegalArgumentException for trailing whitespace in ExtendedMessageFormat argument index#750
dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:argument-index-trailing-ws

Conversation

@dxbjavid
Copy link
Copy Markdown
Contributor

@dxbjavid dxbjavid commented Jun 4, 2026

Unhandled StringIndexOutOfBoundsException on a trailing-whitespace argument index

Reading through readArgumentIndex I noticed that once it has accumulated a digit and then meets whitespace, it calls seekNonWs and immediately does pattern.charAt(pos.getIndex()) again. If that whitespace runs to the end of the pattern the index now equals the length, so a pattern like "{0 " throws StringIndexOutOfBoundsException straight out of the constructor, whereas every other unterminated element ("{0", "{0,number ") reports the documented IllegalArgumentException. I broke out of the loop when the skip reaches the end so it falls through to the existing unterminated-element error. Added a test for the "{0 " case.

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.

1 participant