[SOLVED] Error in rules (Cannot reference the field 'NULL' before it is defined)

Here is my rule

import org.eclipse.xtext.xbase.lib.Functions
import org.joda.time.DateTime

var Number washmachineStartDetected = 0
var DateTime washmachineFinishedAt = NULL
var DateTime washmachineStartedAt = NULL
val org.eclipse.xtext.xbase.lib.Functions$Function1<DateTime, Boolean> washmachineNotify = [
	DateTime washmachineFinishedAt |
		var DateTimeType dt = new DateTimeType(washmachineFinishedAt.toString())
		var String message = String.format("Стирка закончена в %s", dt.format("%1$tH:%1$tM"))
		sendBroadcastNotification(message)
		true
]

rule "WashmachineNotifications"
when
	Time cron "0 0 * * * ?"
then
	if (washmachineSendNotification.state == ON && washmachineFinishedAt != NULL && washmachineFinishedAt.plusMinutes(50).isBefore(now)) {
		washmachineNotify.apply(washmachineFinishedAt)
	}
end

rule "WashmachineOpen"
when
	Item washmachineOpen received update OPEN
then
	washmachineSendNotification.postUpdate(OFF)
end


rule "WashmachineStatus"
when
	Item washmachineCurrent changed
	//Item washmachineCurrent received update
then
	logInfo("washmachineCurrent", washmachineCurrent.toString())

	if (washmachineCurrent.state >= 0.25) {
		washmachineStartDetected = washmachineStartDetected + 1

		//if (washmachineStartDetected == 3) {
		if (washmachineStartDetected == 1) {
			washmachineStartedAt = new DateTime()
			washmachineFinishedAt = NULL
		}
	}
	else if (washmachineCurrent.state == 0) {
		washmachineStartDetected = 0;

		if (washmachineStartedAt != NULL && washmachineFinishedAt == NULL) {
			washmachineStartedAt = NULL
			washmachineFinishedAt = new DateTime()
			washmachineSendNotification.postUpdate(ON)

			washmachineNotify.apply(washmachineFinishedAt)
		}
	}
end

and I got this error

10:40:31.949 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'washmachine.rules', using it anyway:
Cannot reference the field 'NULL' before it is defined
Cannot reference the field 'NULL' before it is defined

What it mean? And how to fix it?

what happens if you change the NULL references to null (lowercase)?

1 Like

null helped me :+1: thank you. But it’s interesting thing :hushed:

Great @lfs_alp5

That finally solved a problem I’ve been facing a long time. :crazy_face:

:slight_smile:

NULL != null

NULL is a special State that an Item can have to indicate it is uninitialized.

null is a programming construct that means no value.

The two are distinct be and not interchangeable.