NPEs, onRequest, and other mysteries of the universe...
A friend wrote to me this morning with an interesting problem. He recently moved his site (hosted at CrystalTech) from ColdFusion 7 to ColdFusion 8. Then he began to get NPEs (Null Pointer Exceptions) in regards to cfquery tags. He would get these about once per 1-2k hits.
But get this - CystalTech recommended adding a blank onRequest:
<cffunction
name = "onRequest"
access = "public"
returnType = "boolean"
output="true">
<cfargument
name = "thePage"
type = "string"
required = "true">
<cfinclude
template="#arguments.thePage#">
<cfreturn true />
</cffunction>
And it worked! He no longer got the NPE error. Now I don't know about you - but I can't imagine any reason why this change would make his error go away. Can anyone else think of a reason why it would help?
As for the NPE in general - one thing I've asked him if is the cfquery was in a CFC and he possibly forgot to var scope. Not that I think it would make a NPE, but the lack of var scoping is something that could lead to random errors like he observed.
Comments
Almost all were tightly wrapped in CRTRY blocks which spit out the NPE error message, although a few on some older, but still active, pages were not in CFTRY blocks and the NPE error message came through the onError method.
Curious, yes?
<cffunction name="onRequest">
</cffunction>
Your onRequest code example isn't blank, thus... is doing something. Hence my confusion. :)
It is my understanding that it generally cannot be cocmpletely empty because you would have to include the page you were wanting to process for it to be rendered.
I have now moved one of my sites to CF8 for testing and have not had an issue - I also use CFC'c.
Terrific! But ... who is going to explain to us why in the world this worked?
This way the visitor doesn't have to be redirected to a login page, the URL in their browser always stays the same.
If anyone knows of any other possible solutions, I'm all ears.
Thanks!


Isn't the only thing special about onRequest() that its a mixin for application.cfc ?