NullPointerExceptions from cfcookie when migrating from Adobe ColdFusion 9 to 10

by kai on 20/12/2013



A few months ago, one of my clients was testing a possible migration from Adobe ColdFusion 9 to Adobe ColdFusion 10. One of the issues they ran into was a NullPointerException when it came to their cookie use.

Something simple such as <cfcookie name=”cfid” value=”574857485748543″> didn’t quite work and resulted in: “The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code. Null Pointers are another name for undefined values.” with that particular line of code being highlighted as the culprit.

Interestingly enough, this code used to work fine for them in Adobe ColdFusion 9. To provide some additional context, here’s a barebone Application.cfc that shows exactly the behaviour:

<cfcomponent>       
  <cfset this.name = "test_app">
  <cfset this.applicationTimeout = createTimeSpan( 2, 0, 0, 0 ) />
  <cfset this.clientManagement = true />
  <cfset this.sessionManagement = false />
  <cfset this.setClientCookies = false />
 
  <cftry>
    <cfcookie name="cfid" value="123456">
 
    <cfcatch>
      Error:<cfdump var="#cfcatch#">
    </cfcatch>
  </cftry>
               
  Cookie:<cfdump var="#cookie#">
 
  <cfabort>
</cfcomponent>

You might be able to guess now what’s causing the issue here: it’s the fact that the cookie’s value is being set in the pseudo-constructor of Application.cfc. If the respective code is moved into onRequestStart for instance, it will just run fine. The code as shown above will work without any issues in ACF 9.

There’s nothing overly wrong with this – it seems to be a funny little quirk when it comes to “changed behaviours” while upgrading from one version of Adobe ColdFusion to another.

Also when dealing with cookies in ColdFusion 10, make sure to look at the links below – some interesting discussions about slightly changed behaviour and functionality:

http://forums.adobe.com/message/4714631
http://www.shilpikhariwal.com/2012/09/prevention-for-accidental-manipulation.html

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: