質問

Update this has been filed as a bug in ColdFusion, https://bugbase.adobe.com/index.cfm?event=bug&id=3546237

I've been having a problem with CF9 and NULL POINTER errors that do not appear to be an issue within Railo. I created a simple CFC and associated mxunit unit test to confirm this with.

On Railo (4.0.4) both unit tests pass. On Coldfusion (9.0.1), the unit test getMetaDataBeforeMethodInvocation fails with NULL POINTER error on the GetMetaData call.

At present I can only surmise that CF9 does not have access to the full metadata following ObjectLoad until a method within that component is called. Is anyone able to shed more light on this problem, and/or offer a better solution than to ensure that a method within the object is called prior to doing getMetaData?

Here is the CFC

// NullError.cfc
component {
    public NullError function init() {
        variables.uuid = CreateUUID();
        return this;
    }
    public string function getUUID() {
        return uuid;
    }
}

and associated unit test

// NullErrorTest.cfc
component extends='mxunit.framework.TestCase' {
    private any function setupTheTests() {
        var o = new NullError();
        debug(o.getUUID());
        // Dump meta data
        debug(GetMetaData(o));
        // Save and load it, and return
        return ObjectLoad(ObjectSave(o));
    }

    public void function getMetaDataBeforeMethodInvocation() {
        var o = setupTheTests();
        // Get meta data, and then get uuid, expecting this to ERROR (NULL POINTER)
        debug(GetMetaData(o)); // CF FAILS HERE, RAILO DOES NOT
        debug(o.getUUID());
    }

    public void function getMetaDataAfterMethodInvocation() {
        var o = setupTheTests();
        // Get uuid, and then get meta data, expecting this to be ok
        debug(o.getUUID());
        debug(GetMetaData(o));
    }
}
役に立ちましたか?

解決

I can confirm this buggy behaviour in both CF 9.0.2 and 10.0.9.

I'd raise a bug if I was you.

The repro case can be simplified a lot from what you have:

// C.cfc
component {}

<!--- test.cfm --->
<cfscript>
o1 = new C();
writeDump(getMetaData(o1)); // OK

o2 = objectLoad(objectSave(o1));
writeDump(getMetadata(o2)); // breaks
</cfscript> 

I don't know what to suggest by way of work-around, given it's so clearly and fundamentally broken.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top