CFMX Generating Vague "java.lang.NullPointerException" Errors...

Posted by Dan on Jul 13, 2005 @ 10:56 AM

I tend to use <cfscript> a lot in my coding, but there are times I find I need to refactor some code portion back to using a tag-based syntax, in order to to use a native CF tag. Yes, I know I could build CF wrapper functions for those tags, but sometimes it's just easier to change the code back.

Usually converting back to a serious of <cfset> tags is no big deal, but occassionally I get some really strange error when I re-run the template. There error gives me almost no detail on the problem, just a very obscure "java.lang.NullPointerException" with no reference to a line number. The full error message is:

The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code.

It looks something like this:


The problem is usually that while cutting-n-pasting my code to <cfset> statements, I've left a rogue semi-colon (;) at the end of one my statements, so I end up with a line of code that looks like:

<cfset lstColumns = listAppend(lstColumns, sValue, ",");>

For whatever reason that trailing semi-colon is easy to miss and the fact that CF gives you absolutely no help in identifying where in the code the problem lies, it can be a pain to find.

So, if you see this error and you've been moving some code from <cfswitch> to tag-based syntax, check for rogue semi-colons!

There are many other reasons this error can be thrown as well—missing parenthesis, missing < or >, lots of stuff really. I just mention the semi-colon issue because it usually throws me off because I know my logic is correct.
Categories: HTML/ColdFusion

Comments for this entry have been disabled.