Handling Java Nulls In ColdFusion
I'm putting the finishing touches on my PowerPoint utils component when I came across a weird Java error. I've seen it before and it may very well be my lack of Java experience that is causing my lack of understanding here.
Say you have a Java method getFoo() that is expected to return a string. I've found that sometimes ColdFusion doesn't properly handle Java nulls so when you try to set a value you'll get something like so when trying to reference it:
ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.
It seems that ColdFusion simply chokes on it. I came up with a hacky fix by passing the value to another method which properly returns an empty string:
<cfargument name="valueToFix" default="" />
<cfset rStr = "" />
<cfif isDefined("arguments.valueToFix")>
<cfset rStr = arguments.valueToFix />
</cfif>
<cfreturn rStr />
</cffunction>
Seems a bit hacky but it works. If someone can shed a little more light on the subject I'd appreciate it.



Your function should save you some keystrokes...I've gotten used to just putting if(isDefined("var")) after all my Java calls.
http://www.bennadel.com/blog/117-Handling-NULL-Val...