[QFJ-666] FIXMessageEncoder got BufferOverflowException when encoding fix mesage Created: 02/Feb/12  Updated: 09/Jun/14  Resolved: 02/Feb/12

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.5.0
Fix Version/s: None

Type: Improvement Priority: Default
Reporter: Zhao Mingyu Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: QuickfixJ, encoding
Environment:

windows server 2003
Java Hotspot VM build 1.6.0_29-b11


Issue Links:
Duplicate
duplicates QFJ-38 FIX Message support double-byte charset. Closed
duplicates QFJ-382 Foreign Language Support - Multibyte ... Closed
is duplicated by QFJ-282 FIXMessageEncoder#encode() may throws... Closed

 Description   

Hi All, I add the code below into my quickfix app, hoping that it could send fix message with multibytes character, such as Chinese.
CharsetSupport.setCharset("GBK");

But I found it failed to send out the fix execution report and throws a BufferOverflowException in method encode of quickfix.mina.message.FIXMessageEncoder.
Below is the code fragment in method encode:

ByteBuffer buffer = ByteBuffer.allocate(fixMessageString.length());
try

{ buffer.put(fixMessageString.getBytes(charsetEncoding)); }

catch (UnsupportedEncodingException e)

{ throw new ProtocolCodecException(e); }

BufferOverflowException is thrown by the code "buffer.put".
The reason is String.length() only return the count of character. For multibytes char, String.length() is half smaller than String.getBytes().length, so the capacity of ByteBuffer is not sufficient for the encoded bytes of the fixMessageString.
Although there is rarely multibytes char in fix message, it can be improved like the below:
ByteBuffer buffer = null;
try { byte[] encodedBytes = fixMessageString.getBytes(charsetEncoding) buffer = ByteBuffer.allocate(encodedBytes.length); buffer.put(encodedBytes); } catch (UnsupportedEncodingException e) { throw new ProtocolCodecException(e); }

 Comments   
Comment by Christoph John [ 02/Feb/12 ]

Hi,
could you please check if one of the tickets QFJ-382 or QFJ-38 fits for you? Maybe you can add a comment there.
Thanks, Chris.

Comment by Zhao Mingyu [ 02/Feb/12 ]

Hi Chris,
I got it. Thanks for your help

Comment by Christoph John [ 02/Feb/12 ]

Great, will close this evil ticket as duplicate then.

Generated at Sat Nov 23 09:01:04 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.