You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Torsten Mielke (Jira)" <ji...@apache.org> on 2026/09/30 12:30:00 UTC
[jira] [Commented] (CAMEL-25137) ArrayIndexOutOfBoundsException: Index -1 when MLLP message starts with segment delimiter
[ https://issues.apache.org/jira/browse/CAMEL-25137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18121137#comment-18121137 ]
Torsten Mielke commented on CAMEL-25137:
----------------------------------------
I will have a closer look...
> ArrayIndexOutOfBoundsException: Index -1 when MLLP message starts with segment delimiter
> ----------------------------------------------------------------------------------------
>
> Key: CAMEL-25137
> URL: https://issues.apache.org/jira/browse/CAMEL-25137
> Project: Camel
> Issue Type: Bug
> Components: camel-mllp
> Reporter: Daisuke Kanai
> Assignee: Torsten Mielke
> Priority: Minor
>
> When MllpTcpServerConsumer receives an MLLP payload where the very first byte is a segment delimiter (0x0D / \r), populateHl7DataHeaders fails with java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds.
> While a leading segment delimiter represents an invalid/malformed HL7 message, the MLLP transport layer should handle malformed payloads gracefully (e.g., throwing a controlled MllpException or passing it to downstream error handlers) rather than crashing with an unhandled runtime exception.
>
> {code:java}
> java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 889 at org.apache.camel.component.mllp.MllpTcpServerConsumer.populateHl7DataHeaders(MllpTcpServerConsumer.java:387) at org.apache.camel.component.mllp.MllpTcpServerConsumer.processMessage(MllpTcpServerConsumer.java:295) at org.apache.camel.component.mllp.internal.TcpSocketConsumerRunnable.run(TcpSocketConsumerRunnable.java:167){code}
>
>
> In MllpTcpServerConsumer.java (around line 387):
> {code:java}
> for (int i = 0; i < hl7MessageBytes.length; ++i) {
> if (fieldSeparator == hl7MessageBytes[i]) {
> fieldSeparatorIndexes.add(i);
> } else if (MllpProtocolConstants.SEGMENT_DELIMITER == hl7MessageBytes[i]) {
> // If the MSH Segment doesn't have a trailing field separator, add one so the field can be extracted into a header
> if (fieldSeparator != hl7MessageBytes[i - 1]) {
> fieldSeparatorIndexes.add(i);
> }
> endOfMSH = i;
> break;
> }
> } {code}
>
> When the payload starts with SEGMENT_DELIMITER (\r), the loop enters the else-if block at i = 0. Evaluating hl7MessageBytes[i - 1] attempts to access hl7MessageBytes[-1], triggering ArrayIndexOutOfBoundsException.
> Additionally, hardcoding hl7MessageBytes[3] as the fieldSeparator assumes the payload strictly begins with MSH|. If leading garbage/delimiters are present, this index misaligns and causes secondary parsing failures.
> While a message not starting with 'MSH' is strictly non-compliant with the HL7 specification, I wanted to share this finding as receiving an unhandled java.lang.ArrayIndexOutOfBoundsException seemed like an unintended behavior.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)