Null Pointers Are Another Name For Undefined Values
Posted June 14, 2006 at 8:28 AM
Launch code in new window » Download code as text file »
- 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:
Launch code in new window » Download code as text file »
- <!--- 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:
Launch code in new window » Download code as text file »
- <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:
Launch code in new window » Download code as text file »
- 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.
Download Code Snippet ZIP File
Post Comment | Ask Ben | Other Searches | Print Page
Newer Post
Search Engine Optimization... Continued
Older Post
SQL LIKE Clause Case Sensitive in ColdFusion MX Query-of-Query
Reader Comments
Hi Ben,
I have same problem on my server now.
Here is my problem code. :)
<cfset startdate = CreateODBCDateTime(startdate)>
Have you found any solution?
First of all... great Web site, Ben! I feel like I must be doing the same type of work at my office, because every day I feel like I'm running into these kinds of problems for which you've already posted an explanation.
Anyway, I have a question related to this problem, and I am wondering if you might have a solution...
As you know, ColdFusion's query-of-query functionality has a lot of unexpected behavior. One of them is that the query object must have declared data types on all columns (you actually wrote another posting about this exact point). My problem, of course, is that all of the columns are ending up as VARCHARS, even when they are not.
So, getting to my problem, I am writing a query-of-query in which I am trying to use a CAST function to convert date columns into the DATE data type, so that when I reference them in the Order By clause, they will actually get sorted as dates.
For example...
SELECT lastVisited,
CAST(lastVisited AS DATE) AS lastVisited_DATE
...
ORDER BY lastVisited_DATE
However, not all columns have dates; some are actually blank. That's where I get the same error message described in your post, because (I believe!) it crashes when trying to convert empty cells to dates.
Do you know of a work-around to this problem?
Thanks for any thoughts you might have!!!
Ben, it's amazing... I think you already helped me. I just saw another blog entry, "ColdFusion Query of Queries and Undefined Cell Values", describing this exact problem, and someone's suggestion to try using the ISNULL function. Thanks... again, great Web site.
@Jason,
Did that work out for you?
Arrrrg!
I am not a cold fusion expert.. not even close
I know just enough to get myself into trouble...and it seems as if I have.
I am getting the error described above when I go to a particular page directly from my browser
http://www.theconnectedinvestor.com/birddogzsites/testsites/birddog.cfm
Sometimes the error comes up sometimes not..
* 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.
(THE ERROR DOES NOT PROVIDE A SPECIFIC LINE OF CODE THAT IS THROWING THE ERROR)
If I refresh the page.. the error does not reappear and I see the actual page everytime.
I just don't know how to debug this error!
Could you tell me what to do to figure out where the issue is? It is very frustrating.
I am on a shared server.
Thank you in advance for any help you might provide!
Best
Laurence
I've started receiving this type of error on a page for a site I've just recently began developing.
Like Laurence, refreshing the page will get rid of the error and the page will function normally. If left for a few minutes it will cause the error again.
The error occurred in /logic/book.cfm: line 34
32 : FROM book_list, book_list_chapter
33 : WHERE book_list.bookID = book_list_chapter.LINKbook
34 : AND book_list.bookID = '#URL.ID#'
35 : AND book_list_chapter.live = 1
36 : ORDER BY book_list_chapter.chapternumber
This is a new host (moving to it since goDaddy seems opposed to upgrading their coldfusion)
I use logic in the OnRequestStart function of my application.cfc to do a cfparam on all my Querystring variables to set defaults. Which is followed by a conditional to ensure that it is a number 0+.
I've looked through my code and cant find anything that would be allowing the variables to become nulls. Plus all date tags I use are fed from results from my queries, which i know all have proper TS values.
This is a common thing when working with certain environments, particularly dynamic database environments. The same error happened to me, I just stored the information into an array, and then tried to reload the page once again using the same params as the user had previously sent. It worked like a charm.
@Laurence,
Is there anyway for you to look at the ColdFusion administrator logs? Or is that all hidden away from you due to the shared nature of your server?
Sometimes, I find that putting a CFFlush at the top of the page (as the very first action of the page request), forces ColdFusion to output a better error message.
@Matt,
Is it possible that you are overriding the "url" value before you run the query?
Application.cfc - OnRequestStart :
<cfparam name="URL.page" default="0">
<cfif NOT isNumeric(URL.page) OR URL.page LT 1>
<cfset URL.page = 0>
</cfif>
and in the page that calls the variable:
...
<cfif URL.page>
<cfquery name="GETchapter" datasource="#application.globvar.DSN#">
SELECT *
FROM book_list_chapter
WHERE LINKbook = #URL.ID#
AND chapternumber = #URL.page#
AND live = 1
</cfquery>
...
the URL.page are not referenced anywhere else between those code blocks.
In random googling, I found this post on the adobe forums: http://forums.adobe.com/thread/56954?start=0&tstart=0
In which some people say it seems to be an old issue with CF8s mySQL driver.
@Matt,
Your original error output didn't reference the URL.page variable, only the URL.id; can the same be said for URL.id? Are you paramming it? Other than that,I don't have any ideas. Might be a bug in the driver.
Ah yeah, I have 2 queries I use, depending on whether page = 0 or not (0 = ToC)
My first post was a ToC attempt, while this latest post was of a specific page.
The error occurred in /logic/book.cfm: line 7
5 : FROM book_list_chapter
6 : WHERE LINKbook = '#URL.ID#'
7 : AND chapternumber = '#URL.page#'
8 : AND live = 1
9 : </cfquery>
I have noticed this fires during queries to my mySQL DB. I've also noticed that when it does, it seems to always target the last variable use as the error.
Such as on another page:
The error occurred in /logic/books.cfm: line 18
16 : <cfcase value="6">book_list.created, book_list.bookname</cfcase>
17 : <cfcase value="7">book_list.created desc, book_list.bookname</cfcase>
18 : <cfdefaultcase>book_list.bookname</cfdefaultcase>
19 : </cfswitch>
20 : </cfquery>
Which is using a switch statement to determine ORDER BY clause.
And I always param all the QS variables I may use across pages in OnRequestStart.
<cfparam name="URL.ID" default="0">
<cfparam name="URL.act" default="view">
<cfparam name="URL.view" default="list">
<cfparam name="URL.filter" default="0">
<cfparam name="URL.sort" default="0">
<cfparam name="URL.page" default="0">
<cfparam name="URL.tar" default="1">
Another note about this issue, is that when I first load a page, it works, and aslong as I continue using it non stop, it'll work. It's only if I stop using oit for a minute or two, then it will explode, but a refresh fixes it again.
According to that adobe forum, it seems like the Helm control panel probably doesnt have this issue. My host uses Cpanel, and I need to email them to get my CF DSN bound to my DBs.
I Guess this is a matter for my host to look into.
Thanks for your time and advice. Your blog is awesome by the way, been using it for years now
@Matt,
Sorry for dropping out of the conversation; did you get the better of this issue?
I had the same problem with a simple insert statement and all variables were defined. I contacted my hosting site hostmysite.com and they fixed the problem.
Tech Support reply below:
I have unchecked the setting to maintain connections across requests for your DSN in Coldfusion and it has cleared the error you were seeing.
@Bill,
Interesting; sounds like some sort of query-structure caching issue.



