The value from key [xxxxxxx] is NULL, which is the same as not existing in CFML

I have been logging this error randomly for a little while now and tried in vain to fully resolve it.
The situation is that vars are set in a structure based on the current template. Code is simply as follows

application.config = {};
application.config.script_bootstrap_popper = '<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>';

savecontent variable="application.appTmpl.body_close_pre" {
    if ( structKeyExists(application.config, 'script_bootstrap_popper') && !isNull(application.config.script_bootstrap_popper) ) {
        writeOutput(application.config['script_bootstrap_popper']);
    }
}

The exception that is “only sometimes (not 100% of the time)” thrown is

the value from key [script_bootstrap_popper] is NULL, which is the same as not existing in CFML

When I log the exception including a dump of the application scope sure enough the key is present and populated so I am a little in the dark on why the exception i sthrown. This only happens when the template is called via an ajax (fetch) call fyi

Any guidance on what I am overlooking would be greatly appreciated.

Don’t forget to tell us about your stack!

OS: Win Server 2019
Java Version: 11.0.4 (AdoptOpenJDK) 64bit
Tomcat Version: 9.0.24
Lucee Version: 5.3.4.77

application scope variables are shared variables across requests, that means that you need to cflock them. I bet this is the problem. Did you use cflock?

application.config = {}; every time might be causing the error, as you have a
you have a potential race condition between requests between line 1 and 2.

don’t reset it, check if it exists before recreating, or try

application.config = {script_bootstrap_popper: etc }; 
2 Likes

That’s a good point, I will check it exists first and see if that solves it.
Thanks for the advice.