Posted in ColdFusion | Posted on 09-12-2007 | 3,586 views
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:
2 name = "onRequest"
3 access = "public"
4 returnType = "boolean"
5 output="true">
6
7 <cfargument
8 name = "thePage"
9 type = "string"
10 required = "true">
11
12 <cfinclude
13 template="#arguments.thePage#">
14
15 <cfreturn true />
16
17 </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.


Isn't the only thing special about onRequest() that its a mixin for application.cfc ?
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 goes in application.cfc =)
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!
[Add Comment] [Subscribe to Comments]