General questions about JSR223 Jython

For adding the rule, what you’re doing should be fine (in my opinion). The reason for the exception is subtle. The RuleSet class constructor that takes an array converts the array to a list internally. However, this list cannot be extended since it uses the provided array as the storage and the array is fixed length. (Note: the Python list is extendable, but it is converted to a Java array when the Java class constructor is called.) I think the JSR223 code should be changed to add the array items to the internal list instead of creating an internal list that can’t be extended.

If you use the default constructor for the RuleSet then you can add rules with addRule. You could alternatively maintain a Python list (theRules = []) and then create the RuleSet with the list when getRules is called.

A few other issues with the Lamp class…

  1. You need to declare theRules as a global variable in the __init__ method.
  2. There’s a typo in getEventTriger. It should be getEventTrigger.
  3. The log statement in the execute method is referencing a Test variable which doesn’t exist (in the example code).

After making those changes the example worked for me.