How to Snoop on ColdFusion Data Types

Last week, I made a couple of posts about ColdFusion Arrays, and how they are actually java.util.Vectors, which means that you can convert them to Java arrays by calling toArray(). How did I figure that out? I didn’t ask the ColdFusion engineers. That’s cheating. The first thing I did was find out what type of class we are actually dealing with when we have a reference to an array. The Java object “Object” (which all objects extend) has a method called getClass() which returns the runtime class of an object. Calling toString() on the class (or simply the act of outputting it, which automatically calls toString()) will reveal the class name:

<cfset cfArray = arrayNew(1)/><cfset cfArray[1] = "c"/><cfset cfArray[2] = "b"/><cfset cfArray[3] = "a"/><html><cfoutput>#cfArray.getClass()#</cfoutput></html>

The result of the code above is:

class coldfusion.runtime.Array

So now I know that I’m dealing with a coldfusion.runtime.Array, however that information doesn’t do me any good by itself. What I need to know is what a coldfusion.runtime.Array really is, and what its public interface looks like. That’s where “javap” comes in. javap is a program that comes installed with your JDK that most people actually don’t know about. I don’t know what the “p” stands for (any ideas?), but javap is essentially a Java class disassembler. Running it against any class in your classpath will, by default, output public and protected method signatures along with other class information (use the -private flag to see private method signatures). If you have java installed and in your path, at the command line, type:

javap java.lang.String

And you will get something like:

Compiled from String.javapublic final class java.lang.String extends java.lang.Object, java.lang.Comparable, java.lang.CharSequence {public static final java.util.Comparator CASE_INSENSITIVE_ORDER;public java.lang.String();public java.lang.String(java.lang.String);public java.lang.String(char[]);public java.lang.String(char[],int,int);public java.lang.String(byte[],int,int,int);public java.lang.String(byte[],int);public java.lang.String(byte[],int,int,java.lang.String)throws;public java.lang.String(byte[],java.lang.String);public java.lang.String(byte[],int,int);public java.lang.String(byte[]);public java.lang.String(java.lang.StringBuffer);java.lang.String(int,int,char[]);public int length();...}

So to find out more about coldfusion.runtime.Array, I used the following command:

javap -classpath /path/to/your/cfusion.jar coldfusion.runtime.Array

The output is:

No sourcepublic final class coldfusion.runtime.Array extends java.util.Vector {public coldfusion.runtime.Array();public coldfusion.runtime.Array(int);static coldfusion.runtime.Array copy(coldfusion.runtime.Array);static coldfusion.runtime.Array copy(java.util.List);public int getDimension();...}

Since I could see from the output above that coldfusion.runtime.Array extends java.util.Vector, I knew that I had access to all of Vector’s public methods, as well, such as toArray(), which was precisely the method I was looking for.

4 Responses to How to Snoop on ColdFusion Data Types

  1. anglisa says:

    Now that I know how to convert a coldfusion array to java array. If I am calling a java function that is returning a java array, how do I convert it to a coldfusion array?Thanks

  2. Jaime Jacinto says:

    Christian Cantrell in his article “Macromedia Flash Remoting Makes Macromedia Flash an Alternative to JSP and Applets” mentioned about Flash Remoting will invoke JSPs.I would like to know how is it done and please, provide me technical example of this.Your help is highly appreciated. Thanks a lot.

  3. scott says:

    This is great info, Christian.I’m really curious how I might convert Java ResultSets and CF Queries back and forth.Using this technique (javap -classpath cfx.jar com.allaire.cfx.DebugQuery), CF Query is a Java object that implements the Query interface.Actually creating a DebugQuery in Java and passing it back doesn’t work though – the data is available, but CF doesn’t quite see it as a query.Anyone have any suggestions?

  4. yellowsign says:

    It would be really nice to have answers to the questions above! Thanks!