isObject() returns true for null

Description

This returns true

isObject( javacast('null','') )

Curiously enough, so does Adobe CF. However, I really do think it's an oversight as I can't think of a good reason right off why null should be considered an object. Especially since all of these return false!

isXML( javacast('null','') ) isArray( javacast('null','') ) isStruct( javacast('null','') ) isBoolean( javacast('null','') ) isSimpleValue( javacast('null','') )

https://trycf.com/gist/a0595c05f8f6de44053224fe527dc052/lucee5?theme=monokai

Related Adobe ColdFusion ticket: https://tracker.adobe.com/#/view/CF-4212825

Environment

None

Activity

Michael Offner 
18 March 2022 at 16:51

that is exactly my point, just to make sure this tests are unrelated and if they are related split them up.

Brad Wood 
14 March 2022 at 16:36

The solution to that is to not re-use the same internal logic between the isObject() method and the part of the engine that validates UDF return types. Or, when validating a UDF return type and full null support is enabled, simply skip the validation check, since null could be anything. Either way, how UDF return types work should not influence how the isObjiect() BIF works as it is an explicit check by the developer.

Michael Offner 
14 March 2022 at 14:26

In my opinion this is not that straight forward. take this example with full null support enabled.

array function testArray() { return null; } object function testObj() {// object is an aloas for any return null; } dump(testArray()); dump(testObj());

null can be used as a placeholder for every type including object. i assume this is the reason isObject return true for null.

please check (and extend test case) with my code above, check if you still can return null when type is object.

Zac Spitzer 
1 March 2022 at 21:02

I reckon there’s no backwards compat issues as any subsequent usage of the null obj as a component would just throw an error

https://github.com/lucee/Lucee/pull/1582

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Created 1 March 2022 at 18:00
Updated 17 May 2023 at 12:51
Resolved 28 March 2022 at 08:31