[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:
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:
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:
{
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!
Is it already reported in the bug system? I couldn't find any issue related to this error.
Regards,
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
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:-)
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.
That -1 thing worked, set a >=0 check at the relevant point and it fixed my problem. Good post, thanks