WebObject.Page Sometimes Returns Nil
I recently reviewed the logs produced by the Web Custom Control demos and noticed that several users had visited the demos and encountered NilObjectExceptions. The logging system, which is upgraded from the current 1.1 release, records the Stack at the time of the exception. Of all things it seems that the culprit was the Home buttons on the demo pages. These buttons simply show the home page (an ImplicitInstance) and close their parent pages (runtime created instances).
Testing revealed an old bug I had noticed in the early days of WE, one which still seems to be an issue. Sometimes WebObject.Page will return nil, but a search of WebObject.Parent will yield the correct page. I’ve added a method to WebControlExt, ClosePageTD, which will attempt to find the page by searching parents, and close it if found. Since rebuilding the demos with that method no errors have been logged.
I can’t reliably reproduce this error in a test project. It happens, but it’s random, so I haven’t submitted a feedback report yet. I have confirmed that sometimes WebObject.Page fails even when no code from Web Custom Controls is present, i.e. it’s not a bug in my toolkit.
The work around method will ship with version 1.2.