Loop-de-loop
Published 1.22.2007 by ~mattg
I’ve been converting numerous projects over the past few weeks in order to try and put conversion through it’s paces. I came across a few projects that crashed the conversion wizard, which I thought odd. It wasn’t an error and a stop, it was one of those nice “this program has encountered an error and must quit” type of errors. Luckily, the log file pointed me to the general area of the problem, and some quick debugging pointed to the problem: infinite recursion.
Now, I’m as dumb as I may seem, and this wasn’t happening all of the time, which was a good thing. My problem was I made some assumptions about the structure of the data which, apparently, are not always true. The data is in a tree, and each record has a field with that record’s parent record id. Pretty simple stuff. The problem, apparently, is that there are some cases in which a record can become it’s own parent. I’m not sure how, but that was causing some infinite recursion in one of my functions, so I fixed it.
This morning, I got the same type of error in the same place. I looked at the offending data and couldn’t find any instances of a record being it’s own parent. I dug a little deeper and realized that somehow, it is also possible to have two records that reference each other. So Record A is the parent of Record B, but Record B is the parent of Record A. This also results in infinite recursion. I ended up using a set to keep track of processed records, and aborted the recursion if I ever got to a position where I was re-processing the same record.
Funny enough, the above records aren’t visible in our product, some somewhere along the way they get excluded for one reason or another.
Filed under .NET Development