Lucee looses static members of component

Hi,

we have a remote function. This function creates an instance of this component:

component {
	this.nState = components.log::STATE_2_SUCCESS; 
	function setNState(arrErr, arrWarn, arrInfo) {
		if (arrayLen(arrErr) > 0)
			this.nState = components.log::STATE_3_ERROR;
		else if (arrayLen(arrWarn) > 0)
			this.nState = components.log::STATE_4_WARNING;
		else
			this.nState = components.log::STATE_2_SUCCESS;
	}
}

components.log.cfc looks like that (simplified):

component output="false" persistent="true" table="table1" accessors="true"{

	static {
		STATE_0_INIT=0;
		STATE_1_RUNNING=1;
		STATE_2_SUCCESS=2;
		STATE_3_ERROR=3;
		STATE_4_WARNING=4;
		STATE_5_TIMEOUT=5;
	}
property name="ID" column="ID" getter="true" setter="false" fieldtype="id" generator="identity";
//others
}

While an external task is calling the remote function, in rare cases we get this Error:

Component from type [components.log] has no accessible static Member with name [STATE_2_SUCCESS]

The failure occurs at this line:

this.nState = components.log::STATE_2_SUCCESS;

What can be the reason that a component looses it’s static members?!

Kind regards
Michael

Hi, please always state which version of Lucee :slight_smile:

Depending on your version, this regression in the current RC might be relevant:

https://luceeserver.atlassian.net/browse/LDEV-3465

This is our current version:

Lucee 5.3.7.43
CentOS Linux release 7.7.1908
Apache/2.4.6 (CentOS)
OpenJDK Runtime Environment (build 1.8.0_252-b09, mixed mode)
Apache Tomcat/8.5.35

Hi,

we still have the problem, that lucee fails to find the static variables (in rare cases):

We tried it in these two ways:

Try #1

component output="false" persistent="true" table="csc_pc_report" accessors="true"{

	static {
		static.TYPE_ENCRYPTION_FILE="encryptionFile";
		static.TYPE_DATA="data";
	}

	public function init(){
		return this;
	}
}

Try #2

component output="false" persistent="true" table="csc_pc_report" accessors="true"{

	static {
		TYPE_ENCRYPTION_FILE="encryptionFile";
		TYPE_DATA="data";
	}

	public function init(){
		return this;
	}
}

We try to access the variable in this way:
csc_pc_report::TYPE_DATA

In rare cases we get the error
Component from type [csc_pc_report] has no accessible static Member with name [TYPE_DATA]

Our environment is:

Lucee 5.3.8.206-1632505525000
Tomcat 8.5.35 x64
Java OpenJDK Runtime Environment (build 1.8.0_252-b09) x64
Linux CentOS Linux release 7.7.1908 (Core)

Kind regards and thanks for your support
Michael

Your #1 syntax shouldn’t be necessary. I always use #2.

When you say “rare”, how often does it happen?

Does it make any different if you access the variables as follows?

GetComponentStaticScope( "csc_pc_report" ).TYPE_DATA

I’ve checked the issue as per the comment from here [LDEV-2932] component looses static functions - Lucee. I got the same error Component from type [test.testcases.LDEV2932.test] has no accessible static Member with name [TYPE_ENCRYPTION_FILE].
I filed a bug [LDEV-3780] Race condition in accessing component static member throws error - Lucee

1 Like

Right, a race condition would seem to explain it, in which case how you access the variable presumably won’t make any difference.

difiicult to say what rare exactly means.
We have a scheduled task which runs on two different servers about 20 times per day on each server. And the scheduled task fails approximately every second day on one of the machines…

Will add this GetComponentStaticScope.thing on one machine and come back with feedback

Thank you and kind regards
Michael

As I say, from what Pothys reports, a race condition is likely to be the cause of your intermittent errors. I doubt changing the syntax will make any difference in that case.

Thanks for clarification. A race condition also came into my mind while experiencing this error…
Is there something we ca do or can this be fixed?

Kind regards
Michael

Hopefully the bug will get fixed promptly, but in the meantime it might be worth trying an intermediate function to get at the static variables to see if that avoids the race condition. For example:

component output="false" persistent="true" table="csc_pc_report" accessors="true"{

	static {
		TYPE_ENCRYPTION_FILE="encryptionFile";
		TYPE_DATA="data";
	}

	public function init(){
		return this;
	}

	public static any function getStaticVar( required string key ){
		return static[ arguments.key ];
	}
}

and then instead of csc_pc_report::TYPE_DATA to access the variable, you would do:

csc_pc_report::getStaticVar( "TYPE_DATA" );

That may be enough, but if not then adding a try/catch around the intermediate function would probably work as a further band aid.

public static any function getStaticVar( required string key ){
	var attempt = 0;
	try{
		attempt++;
		return static[ arguments.key ];
	}
	catch( any exception ){
		if( exception.message.FindNoCase( "has no accessible static Member with" ) && attempt==1 ){
			Sleep( 5 ); //milliseconds to wait
			Retry;
		}
		else
			Rethrow;
	}
	
}

Ok will add that to our code and see if the error occurs again.

Many thanks for the excellent support and kind regards

Michael