[Fixed] ListBase TypeError #1010

Today I spent hours tracking down a bug related to inserting and/or deleting data from a Tree control. In certain circumstances, an update to the underlying dataProvider would cause the following to be reported:

TypeError: Error #1010: A term is undefined and has no properties.
at mx.controls.listClasses::ListBase/makeRowsAndColumnsWithExtraRows()

After a bit of Googling, I found that I am not alone. Other folks have the same issue with Tree. Even more common, it looks like people are getting the same error when manipulating data in an AdvancedDataGrid, in which case it is reported as:

TypeError: Error #1010: A term is undefined and has no properties. at mx.controls.listClasses::AdvancedListBase/makeRowsAndColumnsWithExtraRows()

After drilling down into the Flex Framework source and exploring the makeRowsAndColumnsWithExtraRows function, I added some watch expressions in the Flash Builder Debug pane. (The debug features are really, really useful for this kind of thing.) The culprit? The value for verticalScrollPosition was being reported as -1, causing a line of code to look for an array element at index -1. This array element was in turn undefined, so the error message suddenly makes perfect sense.

The real puzzler here is that verticalScrollPosition could ever be less than zero. This is the logical equivalent of scrolling to the top of the list, then scrolling up one more spot, which is of course impossible. In any case, I have decided to assume that -1 is invalid at all times, and that -1 really means 0. I hope that is a safe assumption!

So, the solution is simple. In my case I had already subclassed the Tree control. If you're using the stock control from the framework, you'll need to subclass it and simply add the following:

override public function get verticalScrollPosition():Number
{
return Math.max(0, super.verticalScrollPosition);
}

All it does is intercept any request for verticalScrollPosition and guarantee that it is greater than or equal to zero. In brief testing, the error has disappeared and I have seen no side effects.

Like anything else on this blog, use this fix at your own risk, since I can't guarantee it won't have any negative impact.

Happy coding!

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
rb's Gravatar hi & thanks for a nice workaround!

Is it already reported in the bug system? I couldn't find any issue related to this error.

Regards,
Robert
# Posted By rb | 5/30/11 8:43 AM
Josh's Gravatar Robert,

I am not aware of this issue existing in the Adobe bug system. The project I was working on is rather complex, so I can't really write out a simple list of steps to reproduce the issue, and therefore I didn't bother reporting it.

Thanks for reading!

-Josh
# Posted By Josh | 6/1/11 1:29 PM
Marty's Gravatar Thanks for posting this! I was pulling my hair out over it. I debugged and found the same thing you did (that verticalScrollPosition was reporting -1) but it didn't occur to me how to fix it. Nice work!
# Posted By Marty | 11/4/11 5:36 PM
Pete's Gravatar I'm going to be nice to people all day now, because you solved this thing for me. You deserve a Nobel Peace Prize. Great work!
# Posted By Pete | 12/22/11 10:50 AM
Brian Bishop's Gravatar Hey. Lovely, was getting the same bug, will check now if the list has a -1 vertical position.

May I ask, what did you mean bu "watch expressions in the Flash Builder Debug pane". I'll look it up in the meantime, but it might be a good response under this article:-)
# Posted By Brian Bishop | 1/24/13 8:15 AM
Josh's Gravatar Brian, the Flash Builder Expressions View is explained in this article by Adobe: http://help.adobe.com/en_US/Flex/4.0/UsingFlashBui...

Note that you can highlight an expression in your source, right click, and select Create Watch Expression. It also might be a good idea to place a breakpoint nearby. Then when debugging the app, you should see an Expressions tab somewhere (top-right panel of the Flash Debug perspective by default, I think) which will list out everything you are currently watching.
# Posted By Josh | 1/24/13 10:42 AM
Brian Bishop's Gravatar Ah, thanks. Thought you were talking about watching something in the Console... indeed, spend most of my working day in the Debug Pane already:-0)

That -1 thing worked, set a >=0 check at the relevant point and it fixed my problem. Good post, thanks
# Posted By Brian Bishop | 1/24/13 11:39 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner