[QFJ-39] ClassCastException in MessageCracker Created: 24/Jul/06  Updated: 02/Sep/06  Resolved: 24/Jul/06

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.0.1
Fix Version/s: 1.0.2

Type: Bug Priority: Default
Reporter: Eddie Robertsson Assignee: Steve Bate
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows XP, Java 1.5.0_07



 Description   

QuickFIX didn't respond correctly to a ResendRequest from our counterparty.

Normally this is what happens when I have to restart during the day:

XXX = Me
YYY = Counterparty

8=FIX.4.29=5335=A34=720049=XXX52=20060718-08:07:30.23156=YYY10=108
8=FIX.4.29=6635=A34=720149=XXX52=20060718-08:07:30.26156=YYY98=0108=18010=195
8=FIX.4.29=6635=A34=1422549=YYY52=20060718-08:07:29.59656=XXX98=0108=3010=212
8=FIX.4.29=6235=234=720249=XXX52=20060718-08:07:32.13456=YYY7=116=010=222
8=FIX.4.29=7535=134=720349=XXX52=20060718-08:07:32.13456=YYY112=ResendHasFinished10=224

ResendRequest from YYY:
8=FIX.4.29=6635=234=1422649=YYY52=20060718-08:07:29.60056=XXX7=715016=010=182

Correct respons from QuickFIX/J:
8=FIX.4.29=9435=434=715043=Y49=XXX52=20060718-08:07:32.18456=YYY122=20060718-08:07:3236=7204123=Y10=080
8=FIX.4.29=7535=134=720449=XXX52=20060718-08:07:38.14356=YYY112=Test
OS, 10:07:3810=149
8=FIX.4.29=7535=134=720549=XXX52=20060718-08:07:41.14756=YYY112=Test
OS, 10:07:4110=142

Yesterday's scenario:

8=FIX.4.29=6735=A34=3049949=XXX52=20060718-11:29:33.50456=YYY98=0108=18010=004
8=FIX.4.29=6735=A34=6125449=YYY52=20060718-11:29:34.08356=XXX98=0108=18010=000
8=FIX.4.29=6335=234=3050049=XXX52=20060718-11:29:36.72856=YYY7=116=010=023
8=FIX.4.29=7635=134=3050149=XXX52=20060718-11:29:36.73856=YYY112=ResendHasFinished10=026

ResendRequest from YYY:
8=FIX.4.29=6735=234=6125549=YYY52=20060718-11:29:34.08756=XXX7=3049816=010=249

The correct Sequence Reset message is missing from QuickFIX/J...

8=FIX.4.29=7635=134=3050249=XXX52=20060718-11:29:42.75756=YYY112=Test
OS, 13:29:4210=201
8=FIX.4.29=7635=134=3050349=XXX52=20060718-11:29:45.76156=YYY112=Test
OS, 13:29:4510=203

When checking the Event log I found the following:

20060718-11:29:31.220: Session FIX.4.2:XXX->YYY schedule is daily,
00:00:00 UTC - 00:00:00 UTC
20060718-11:29:31.241: Created session: FIX.4.2:XXX->YYY
20060718-11:29:33.554: Initiated logon request
20060718-11:29:36.728: Received logon response
20060718-11:29:36.728: MsgSeqNum too high, expecting 1 but received 61254
20060718-11:29:36.738: Sent ResendRequest FROM: 1 TO: 0
20060718-11:29:36.788: Received ResendRequest FROM: 30498 TO: 0
20060718-11:29:36.819: Error during message processing
java.lang.ClassCastException: quickfix.Message
at quickfix.MessageCracker.crack(MessageCracker.java:48)
at trader.quickfix.QuickFIXApplication.toApp(QuickFIXApplication.java:373)
at quickfix.Session.resend(Session.java:757)
at quickfix.Session.nextResendRequest(Session.java:698)
at quickfix.Session.next(Session.java:585)
at quickfix.mina.ThreadPerSessionEventHandlingStrategy$MessageDispatchingThread.run(ThreadPerSessionEventHandlingStrategy.java:75)



 Comments   
Comment by Steve Bate [ 24/Jul/06 ]

Eddie,

I've done some investigation on this issue and there is something strange. The log file indicates the messages are FIX 4.2 but the MessageCracker is failing because the resent message BeginString is FIX.4.3 and the message being resent is not a subclass of quickfix.fix43.Message. I'd expect the latter because the messages are FIX 4.2 and I assume a FIX 4.2 message factory is being used. However, I'm not sure how the message would have a FIX 4.3 BeginString. Do you have any ideas? Did you switch the FIX version during the session so that some messages in the store had differing FIX versions in the BeginString?

Steve

Comment by Eddie Robertsson [ 24/Jul/06 ]

Steve,

Hmm, how do you now the MessageCracker is failing because the resent message BeginString is FIX.4.3?

Both me and the coutnerparty are using FIX.4.2 and I just rechecked the message log from the day when the problem occurred and all messages in that log are FIX.4.2. However, I just checked the BugReport and it seems that the normal FIX field delimiter has been removed when I pasted the messages in the BugTracker. Hence, it appears that the start of the message is 8=FIX.4.29=7635... when it really should be 8=FIX.4.2|9=7635...

Other than that I have no clue as to why any messages would have a FIX 4.3 BeginString and I can't find any of those messages in my FIX logs either.
Cheers,
/Eddie

Comment by Steve Bate [ 24/Jul/06 ]

OK, the stack trace was confusing me. The line 48 doesn't correspond to a source code line that could raise class cast exceptions (it's between two lines that could raise it). After more looking, I think I see what's happening. I'm curious. Why are you using the message cracker in the toApp method? Normally, it's used in the fromApp method to delegate to a a type-safe method for processing an incoming message.

The session is creating a generic Message for the resend and that's what's causing the ClassCastException in the message cracker which is looking for a message subtype corresponding to the FIX version. I will modify the Session class to create a message of the correct subtype using the specified message factory but I'm still curious about your use of MessageCracker.

Steve

Comment by Eddie Robertsson [ 24/Jul/06 ]

I'm using the message cracker in the toApp in the same way,

Comment by Eddie Robertsson [ 24/Jul/06 ]

I'm using the message cracker in the toApp in the same way, to delegate to a type-safe method for further pro

Comment by Eddie Robertsson [ 24/Jul/06 ]

Appologize for the multiple posts but apparently Ctrl+Enter submits the comment...

I'm using the message cracker in the toApp in the same way, to delegate to a type-safe method for further processing. For example, I use it to catch when QuickFIX is sending Heartbeats that may indicate a faulty connection.

Would it be easy for me to modify the Session class so I don't have to wait for a new release?

Thanks,
/Eddie

Comment by Steve Bate [ 24/Jul/06 ]

What I'm planning to do is modify the nextResendRequest method in Session.java. There is a line...

Message msg = new Message((String) messages.get, dataDictionary);

in the loop where message are reconstructed from the strings in the message store. I intend to replace with something like...

String msgString = (String)messages.get;
Message msg = messageFactory.create(
MessageUtils.getStringField(msgString, 8), // BeginString
MessageUtils.getMessageType(msgString));
msg.fromString(msgString, dataDictionary, false);

It's a bit uglier and requires some preparsing of the message, which is why is wasn't done before. However, I
didn't anticipate users using the MessageCracker for type safe dispatching of outgoing messages (not that there
is anything wrong with it).

I'm going to modify my ATApplication (acceptance test) to use a MessageCracker in toApp. This should recreate the problem since several of the acceptance tests trigger message resends. I'll then make the changes above and ensure all the tests still pass. If you make the changes first and it seems to work (or not), please tell me. Thanks.

Comment by Eddie Robertsson [ 24/Jul/06 ]

Steve,

I've done the modifications you suggested and done some initial testing. Unfortunately the problem didn't occur everytime a ResendRequest was initiated by the counterparty. However, the modified code seems to work fine so I'll keep testing and check if the ClassCastException reappear.

Thanks and keep up the good work!
/Eddie

Comment by Steve Bate [ 24/Jul/06 ]

The fix has been committed to the 1.0.x branch and to the trunk.

Generated at Mon Apr 29 16:20:12 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.