• 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.

A co-worker of mine was getting this ColdFusion error message the other day and I was helping him debug the problem. Not knowing anything about his code, the problem was not obvious. I was looking for reference to undefined variables and other more obvious red flags. After dumping out a bunch of variable scopes it seems that all variables existed and had values or empty strings in them.

Since empty string is just a string value, I didn't give it much thought until I then went back to the line that was throwing the error. It was a DateDiff() method call. Then it was obvious. The problem was not that variables and values didn't exist, it was that a ColdFusion DATE/TIME object could not be created based on the variable value.

This is essentially what was causing the error:

  • <!--- Set values that are expected to have date/time values. --->
  • <cfset dtOne = "" />
  • <cfset dtTwo = "" />
  •  
  • <cfif DateDiff( "d", dtOne, dtTwo)>
  • <!--- Ha ha, you get an error. --->
  • </cfif>

This seems like a very cryptic error. Let's now compare it to one where a non-date object is passed to a function:

  • <cffunction name="TestDateValue" returntype="void">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="Value" type="date" required="yes" />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  •  
  • </cffunction>
  •  
  • <!--- Attempty to call the above function with a bunk value. --->
  • <cfset TestDateValue( "" ) />

This, of course, throws an error because the value being passed into TestDateValue() is [""] which is NOT a date value. The error is very obvious and self-explanatory:

  • The argument VALUE passed to function TestDateValue() is not of type date.

It would be nice if the DateDiff(), DateAdd(), and other such functions could throw similar errors. It makes me curious as to how those functions are working behind the scenes to validate variables.