Does Lucee support optional chaining with the question mark?

This code works, but I can’t find anything in the documentation mentioning support for Optional Chaining.

myObj = {} = 'bar'
writeOutput("*" & myObj?.foo & "*")
writeOutput("*" & myObj?.blah & "*")

IsNull chokes on it, which is odd. It doesn’t seem to be evaluating to blank or to null. I couldn’t call getMetaData on it either (I got the same exception as below when trying to use isNull).

Yeah, it seems to be a valid bug. Please file a bug on Jira. It’s working fine on Lucee 6.

I’m seeing more strangeness with this operator. The combination of using it in this if statement, and later trying to cfdump something, causes a strange exception I have never seen before. If I change either one of these things (remove the question marks or remove that 2nd cfdump) then everything works fine.

I’m on Lucee, Tomcat 9.0.83, JVM 11.0.21.

Ok, I’ve isolated the problem. This code produces your error.

    message = { message = { content = "content1" } };
    local.apiData = { choiches = [ message, message ]  };

The question mark generates the error.
On TryCf, it is not enough to remove the question mark to avoid having the problem but you have to reload the entire page.

How you can see:


1 Like

Again. It seems that the problem is the “local” scope:

this works:

this not:

with this Error:
Expecting a stackmap frame at branch target 139 Exception Details: Location: main1704779588574_4f49f5e6_b5fc_8b3d_384f_1a57b73e05c1_cfm7020$;)Ljava/lang/Object; @5: iconst_1 Reason: Expected stackmap frame at this location. Bytecode: 0x0000000: 2bb6 0031 4d04 9900 822b 2bb6 0035 2ab4 0x0000010: 0039 0332 2b04 bd00 3b59 032a b400 3904 0x0000020: 322b 03bd 003b b800 40b8 0046 53b8 0040 […]

(Refresh page any changes after the error!)

1 Like

Thank you @Roberto_Marzialetti, for narrowing it down. :slight_smile:

For me, when the error occurred, I had to save my file as a completely new file to get the error to go away. Even after changing the code. I could remove all the code in the file, and refresh, and the error still persisted. Even after a Lucee restart. And I did clear all the caches in the Lucee admin also. Very strange.