Skip to content

Conversation

@dilyanpalauzov
Copy link
Contributor

@dilyanpalauzov dilyanpalauzov commented Oct 19, 2025

Before this change openhab/rules/b.rules:

val a = 1
val b = a + 2

rule "B"
when Item b changed
then 
  logError("B", Integer.toString(b))
end

emitted

[INFO ] [el.core.internal.ModelRepositoryImpl] - Loading DSL model 'b.rules'
[WARN ] [e.runtime.internal.RuleContextHelper] - Variable 'b' on rule file 'b.rules' cannot be initialized with value '<XFeatureCallImplCustom> + <XNumberLiteralImpl>': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_plus(int,int) on instance: null

and during execution

[ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'b-1' failed: An error occurred during the script execution: Could not invoke method: java.lang.Integer.toString(int) on instance: null in b

With the current change the above produces:

[INFO ] [el.core.internal.ModelRepositoryImpl] - Loading DSL model 'b.rules'
[ERROR] [org.openhab.core.model.script.B     ] - 3

Closes: #3696
Closes: #4493.

@dilyanpalauzov dilyanpalauzov requested a review from a team as a code owner October 19, 2025 11:30
@dilyanpalauzov
Copy link
Contributor Author

This also works as expected:

val lock = new java.util.concurrent.locks.ReentrantLock
var a = 1
val ()=>String b = [
  lock.lock
  a++
  lock.unlock
  Integer.toString(a)
]

rule "B1"
when Item b changed
then
  logError("B1", b.apply)
end

rule "B2"
when Item b changed
then
  logError("B2", b.apply)
end

@holgerfriedrich
Copy link
Member

Why do you remove getVariableDeclaration? I can't find where it is used, but do I overlook any specific reason why it needs to be removed.....

@dilyanpalauzov
Copy link
Contributor Author

The only usage of RuleContextHelper is:

$ git grep -n RuleContextHelper
bundles/org.openhab.core.model.rule.runtime/src/org/openhab/core/model/rule/runtime/internal/DSLRuleProvider.java:214: IEvaluationContext context = RuleContextHelper.getContext(ruleModel);
bundles/org.openhab.core.model.rule.runtime/src/org/openhab/core/model/rule/runtime/internal/RuleContextHelper.java:36:public class RuleContextHelper {
bundles/org.openhab.core.model.rule.runtime/src/org/openhab/core/model/rule/runtime/internal/RuleContextHelper.java:47:Logger logger = LoggerFactory.getLogger(RuleContextHelper.class);

The method RuleContextHelper.getVariableDeclaration() is deleted, because it is not called from anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

var in lambda DSL global functions ignore global variables

2 participants