[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 |
Issue Links: |
|
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. But I found it failed to send out the fix execution report and throws a BufferOverflowException in method encode of quickfix.mina.message.FIXMessageEncoder. ByteBuffer buffer = ByteBuffer.allocate(fixMessageString.length()); 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, |
Comment by Zhao Mingyu [ 02/Feb/12 ] |
Hi Chris, |
Comment by Christoph John [ 02/Feb/12 ] |
Great, will close this evil ticket as duplicate then. |