As some of you know I do web application development. The languages of choice for my current employer is coldfusion and java with some flex thrown in there for good measure. Last Friday I began experience a very odd bug with the two so decided I would share my findings with the world.
The problem was I was returning a object of type List with a collection of Result objects. Result was a object I created that extended HashMap. For those who don’t know coldfusion automatically maps a List object to an Array in coldfusion and a Map (or HashMap) object to a Struct. This was working on Thrusday but for some reason stopped on Friday.
The issue I was expereiencing was when I was trying to retreive information out of the Result object in coldfusion I was not able to use the dot notation:
Not wanting to rewrite my code I attempted several fixes to get around this. First I discovered that if I did a IsStruct the object was of type struct. Next I checked the list of keys using StructKeyList. This too showed me that “someElement” was a part of my structure. Finally I tried a StructFind(currentResult, “someElement”) which is essentially the same as the above code but for some reason coldfusion found the value this time.
So I went back to the drawing board. I didn’t want to rewrite all my existing code to use StructFind, because eventually someone would come along (probably me) and try to revert it to the more clean syntax using the dot notation. So I attempted to cast the Result object to a Map before I put it into the List on the java side. This didn’t work either.
Finally I found a solution that seemed to work. I used the coldfusion Duplicate method to do a deep copy of the structure to itself:
currentResult = Duplicate(currentResult)
This seems to be working and now I just have to explain why I did one crazy thing instead of a million.