Bug in clearFlash() method of "client" flash implementation object

I believe I’ve found a bug in the implementation of the clearFlash() method of the ColdBox.system.web.flash.ClientFlash object. I’ve noticed that this method doesn’t behave the same as the same method of the SessionFlash implementation. Specifically, it doesn’t appear to actually remove any items from the flash storage struct.

I’ve tested this using ColdBox 3.0 RC2 running ColdFusion 8.0.1 on Windows Server 2003 with the client scope configured to store variables in a MS SQL Server database.

ClientFlash.cfc uses the clearFlash method inherited from AbstractFlashScope, but this default implementation doesn’t seem to work with client variables. The structDelete function on line 73 only appears to “kind of” remove items from the client structure. I say “kind of” remove because using FusionDebug to inspect this struct shows that the removed items are replaced with an item called “coldfusion.util.FastHashRemoved”. Then the structIsEmpty call on line 78 returns false because the struct still contains these FastHashRemoved items. In fact, the original items don’t appear to have been removed from the struct at all because they are inflated again during the next request.

Just to make sure I wasn’t going crazy, I ran the unit tests in ClientFlashTest.cfc and testClearFlash failed consistently.

In summary, there seems to be some issues with the structDelete() and structIsEmpty() functions not working correctly with the client struct used to store the flash RAM objects.

After some more testing, it appears that the coldfusion.util.FastHashRemoved stuff may be an artifact of the FusionDebug debugger. The structDelete function does appear to be deleting the items from the struct. But the odd thing I’m seeing is that there should be three items in my flash RAM storage, and FusionDebug is correctly showing three items in the ‘scope’ struct. But if I run structCount(scope) it returns 6! If I run structKeyList(scope) I only see the three keys that I expect. But there appears to be three “hidden” keys in this struct, so after clearFlash() deletes them there are still three left (the hidden ones) causing structIsEmpty() to evaluate to false. This is really strange…

Alright, I’ve narrowed it down to a bug/issue with the serialization algorithm used by the ObjectMarshaller object when running ColdFusion 8.

When a struct is deserialized, structCount() returns double the number of items in the structure. There appears to be a ‘hidden’ item for each visible item. Here is some code used to test this:

hmm, this works as expected on cf9, weird.
Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

There might be a better solution, but it appears that if you duplicate the struct with structCopy() that the duplicate struct has the correct count. So a quick fix would be to check if the deserialized object is a struct and if so then copy it and return the duplicate struct.

Here’s my modified version of deserializeGeneric that resolved the issue for me. The only change from the original function is the if statement right before the “return obj” line at the end. Maybe you can get this quick fix in before your 3.0 release.

Richard,

I am a little hesitant on this, as it seems weird to do a struct copy on the structure to fix this. I believe this is isolated to cf8, and will test once more on cf8, because railo and cf9 all is good. Anyways, thanks for this.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com