2

更新 这已作为 ColdFusion 中的错误提交,https: //bugbase.adobe.com/index.cfm?event=bug&id=3546237

我一直遇到 CF9 和 NULL POINTER 错误问题,这在 Railo 中似乎不是问题。我创建了一个简单的 CFC 和关联的 mxunit 单元测试来确认这一点。

在 Railo (4.0.4) 上,两个单元测试都通过了。在 Coldfusion (9.0.1) 上,单元测试 getMetaDataBeforeMethodInvocation 失败,并在 GetMetaData 调用上出现 NULL POINTER 错误。

目前我只能推测 CF9 在调用该组件中的方法之前无法访问 ObjectLoad 之后的完整元数据。与确保在执行 getMetaData 之前调用对象中的方法相比,是否有人能够更清楚地说明这个问题,和/或提供更好的解决方案?

这里是 CFC

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

和相关的单元测试

// 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));
    }
}
4

1 回答 1

1

我可以在 CF 9.0.2 和 10.0.9 中确认这种错误行为。

如果我是你,我会提出一个错误。

复制案例可以从您拥有的内容中简化很多:

// C.cfc
component {}

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

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

我不知道通过变通方法建议什么,因为它是如此明显和根本上被破坏了。

于 2013-04-21T00:29:01.677 回答