Skip to content

Conversation

dilyanpalauzov
Copy link

I cannot get this example working, as it is.

This works:

public class DisableThing extends helper.generated.Java223Script {
    public void main() {
        thingManager.setEnabled(_things.network_pingdevice_mything().getUID(), false);
    }
}

If the import was necessary, then import org.openhab.core.thing.ThingManager; is correct and import org.openhab.core.automation.ThingManager; provides errors.

import org.openhab.core.thing.ThingManager;

public class DisableThing extends helper.generated.Java223Script {
    public void main() {
        ThingManager thingManager;
        thingManager.setEnabled(_things.network_pingdevice_mything().getUID(), false);
    }
}

fails with

2025-10-03 10:37:32.456 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script '/etc/openhab/automation/jsr223/DisableThing.java': /DisableThing.java:6: error: variable thingManager might not have been initialized
        thingManager.setEnabled(_things.mqtt_topic_r9().getUID(), false);
        ^

Also

import org.openhab.core.thing.ThingManager;
import org.openhab.automation.java223.common.InjectBinding;

public class DisableThing extends helper.generated.Java223Script {
    public void main() {
        @InjectBinding ThingManager thingManager;
        thingManager.setEnabled(_things.network_pingdevice_mything().getUID(), false);
    }
}

produces

2025-10-03 10:38:36.683 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script '/etc/openhab/automation/jsr223/DisableThing.java': /DisableThing.java:6: error: annotation interface not applicable to this kind of declaration
        @InjectBinding ThingManager thingManager;
        ^

This again works:

import org.openhab.core.thing.ThingManager;
import org.openhab.automation.java223.common.InjectBinding;

public class DisableThing extends helper.generated.Java223Script {
    @InjectBinding ThingManager thingManager;
    public void main() {
        thingManager.setEnabled(_things.network_pingdevice_mything().getUID(), false);
    }
}

That said, I do not know what exactly this example wants to demonstrate, as there are many possibilites.

@dalgwen
Copy link
Owner

dalgwen commented Oct 3, 2025

I suppose that the import declarations you removed was a remnant of a bad copy/paste.
Thanks.


Yes, injection of the ThingManager (or any other openHAB value) into variable won't happen inside a method.
As the doc says, the only valid injection points are:

  • class field
  • method parameter (when the method is executed by the bundle directly)
  • constructor parameter (when the java223 bundle is the one creating the instance)

Does the fact that you tried to do this means that the documentation is not good enough ?

@dalgwen dalgwen merged commit 7feb0b2 into dalgwen:java223/main Oct 3, 2025
@dalgwen
Copy link
Owner

dalgwen commented Oct 3, 2025

That said, I do not know what exactly this example wants to demonstrate, as there are many possibilites.

This example just shows that the thingManager is accessible from script.
It is not a standard openHAB JSR223 injection (I think other languages don't have it ?), so I thought it deserved a dedicated example.

@dilyanpalauzov dilyanpalauzov deleted the j233_rm_thingmanager branch October 3, 2025 13:10
@dilyanpalauzov
Copy link
Author

As the doc says, the only valid injection points are: …

Where is this stated exactly?

For me this part of the documentation is clear, but it could be stated that thingManager serves only ot disable and enable things, while ruleManager serves only to disable and enable rules, and to runNow().

And also including hyperlinks to the documentation of classes implementing thingManager, metadataRegistry, and ruleManager. E.g. in a table like https://github.com/openhab/openhab-docs/pull/2569/files .

If access to metadataRegistry, ruleManager and thingManager are useful for OH automation, can you propose including them in one of the presets, offered by JSR 223-OH?

For @InjectBinding I think it should be mentioned, that it is needed only for objects, which are not injected by default. Is this correct?

I have not tried to use that helper.rules.eventinfo package, but e.g. src/helper/java/helper/rules/eventinfo/ItemCommand.java contains:

@InjectBinding(named = "event.itemName") protected @NonNullByDefault({}) String itemName;
@InjectBinding protected @NonNullByDefault({}) Command command;

and the bottom of https://www.openhab.org/docs/configuration/jsr223.html says for core.ItemCommandTrigger:

Parameter 	Description
itemName 	The name of the Item
command 	The Command (optional)
  • Why named= above includes event. but event. it is not mentoned on jsr223.html?
  • Will it still work, if the second @InjectBinding is removed?

Another discrepancy, at https://www.openhab.org/docs/configuration/jsr223.html for core.ItemStateChangeTrigger is stated

Parameter 	Description
itemName 	The name of the Item
previousState 	The previous State (optional)
state 	The State (optional)

but helper.rules.eventinfo.ItemStateChange has:

@InjectBinding(named = "event.itemName") protected @NonNullByDefault({}) String itemName;
@InjectBinding() protected @NonNullByDefault({}) State oldState;
@InjectBinding() protected @NonNullByDefault({}) State newState;

@dilyanpalauzov
Copy link
Author

Pre-made event objects that you can use as a parameter in a rule are defined in the package helper.rules.eventinfo. You can define your own if some are missing (do not hesitate to make a Pull Request)

Also an example with an helper.rules.eventinfo. object would be good.

@dalgwen
Copy link
Owner

dalgwen commented Oct 4, 2025

Where is this stated exactly?

in Variable injection

For me this part of the documentation is clear, but it could be stated that thingManager serves only ot disable and enable things, while ruleManager serves only to disable and enable rules, and to runNow().

Good idea. I added a table like the one you mentioned, with a "purpose" column

If access to metadataRegistry, ruleManager and thingManager are useful for OH automation, can you propose including them in one of the presets, offered by JSR 223-OH?

I will make a PR to include the java223 bundle in openhab addon later this year.
And I think this is one thing that would be interesting to talk about.

For @InjectBinding I think it should be mentioned, that it is needed only for objects, which are not injected by default. Is this correct?

In the documentation, I said it is for more control on the injection process, and preset. And the comments in the linked example try to explain it further. I though example was better suited for this. I'm open for a rewrite if you think it's not sufficient.

Why named= above includes event. but event. it is not mentioned on jsr223.html?

It's because it's two different things. On the page you mention, it is to define a trigger for a rule.
But in the example I wrote, it is a value injected in the context of the resulting action, when the rule is triggered.
If you seek equivalent in other jsr223 language, it is here for javascript.
That said, I think this information that we can found in the jsr223 javascript documentation should maybe be in the global jsr223 page. After all, it is not language related (I didn't do anything to have the 'event' object in the context). In fact I had difficulties to found equivalent information when I wrote my bundle and have to debug with trial/error (didn't though about looking in other jsr language, stupid me).
I did the eventinfo package exactly for this : I don't want users (or me) to have to go to the documentation, or having error and spamming the community topic, especially when that said documentation it a bit lacking. I'd rather rely on hardcoded object. I also think that code is sometimes better to find information (especially for this bundle, as you can use auto completion in your IDE to find directly what you want)
I'm ashamed to say so, but even if the core jsr223 documentation is very important, it's, for now, low on my priority list 😅. (so feel free if you want, and by the way many thanks for the work you already did)

Will it still work, if the second @InjectBinding is removed?

Yes it will work, but as indirectly stated in a comment in the InjectBindind example, when using InjectBinding like this, you automatically have the mandatory attribute to 'true' by default. I did this to fail faster if something is unexpected (for example, some openHAB change in the name of the injected value).

but helper.rules.eventinfo.ItemStateChange has:

Same as above, it's two different things (trigger definition, and value injection in the resulting triggered action)

@dalgwen
Copy link
Owner

dalgwen commented Oct 4, 2025

Also an example with an helper.rules.eventinfo. object would be good.

I have one, but it could have a little boost in visibility by linking to it from other parts of the documentation. I will do so

@dilyanpalauzov
Copy link
Author

It is hard to find example for an rules.eventinfo. class in README.md, because README.md does not contain the string eventinfo in the examples. So when the parameter of a @Rule annotated method is of type eventinfo.ItemStateChange, then the parameter has properties itemName, oldState and newState, which are handled by that annotation.

I proposed at openhab/openhab-docs#2582https://deploy-preview-2582--openhab-docs-preview.netlify.app/docs/configuration/jsr223.html#triggertype-objects-all-jsr223-languages to document on the All openHAB Automation Add-Ons JSR223 page what the content of inputs in the fired SimpleRule.execute(Action module, Map<String, ?> inputs) is. So for core.ItemStateChangeTrigger the fields are oldState, newState, lastStateUpdate, lastStateChange, event and source, but eventinfo.ItemStateChange contains source ⇔ itemName and missest lastStateUpdate and lastStateChange.

I thought until now that @InjectBinding is only handling data from ScriptEngine.put()/.scopeValues(), but when handling SimpleRule.execute() there is no preceeding scriptEngine.put(). So @InjectBinding does not do the initialization based on scriptEngine.put().

From helper/rules/eventinfo/ItemStateChange.java:

@InjectBinding(named = "event.itemName") protected @NonNullByDefault({}) String itemName;

Is itemName taken from the org.openhab.core.automation.events.TimerEvent.getPayload(), from inputs.get('source'), or from where? I have not looked in the BindingInjector implementation,but I have the feeling this syntax with fullstop in named= is not documented.

Can this eventinfo/ItemStateChange annotation be used on a Java-method, which is part of SimpleRule, but has no @Rule annotation and does not inherit from the Java223Script class?

Besides a core.ItemStateChangeTrigger receives a ItemStateChangedEvent and I guess core.ItemStateUpdateTrigger receives ItemStateUpdatedEvent. But here

    @ItemStateUpdateTrigger(itemName = Items.my_detector_item, state = OnOffType.ON.toString())
    @ItemStateUpdateTrigger(itemName = Items.my_otherdetector_item, state = OnOffType.ON.toString())
    public void myRule(ItemStateChange inputs) { // <-- HERE, strongly typed parameter

I think it is mixed: an ItemStateUpdateTrigger supplies data for ItemStateChange handler, the parameter probably should be eventinfo.ItemStateUpdate.

If a rule has triggers of two distinct types:

import org.openhab.core.config.core.Configuration
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule
import org.openhab.core.automation.*
scriptExtension.importPreset("RuleSupport")

automationManager.addRule(new SimpleRule() {
    @Override
    Object execute(Action module, Map<String, ?> inputs) {
    }

    List<Trigger> triggers = [
      TriggerBuilder.create().withId("trig1").withTypeUID("core.ItemStateChangeTrigger")
      .withConfiguration(new Configuration([itemName: "d1"])).build(),
      TriggerBuilder.create().withId("cr2").withTypeUID("core.ItemStateChangeTrigger")
      .withConfiguration(new Configuration([itemName: "d2"])).build()
    ]
})

Can as parameter values be used execute(eventinfo.ItemStateChange d1, eventinfo.ItemStateUpdate d2) , so one extra parameter? It makes sense, but I think this cannot work.

@InjectBinding protected @NonNullByDefault({}) Command command;
Will it still work, if the @InjectBinding is removed?
Yes it will work, but as indirectly stated in a comment in the InjectBindind example, when using InjectBinding like this, you automatically have the mandatory attribute to 'true' by default. I did this to fail faster if something is unexpected (for example, some openHAB change in the injected value).

I suggest removing all not needed @InjectBindings, so that it is clear what they do and do not do, unless there is some performance impact having explict @InjectBinding present, which impact is not yet described.

@dalgwen
Copy link
Owner

dalgwen commented Oct 8, 2025

So for core.ItemStateChangeTrigger the fields are oldState, newState, lastStateUpdate, lastStateChange, event and source, but eventinfo.ItemStateChange contains source ⇔ itemName

I do have itemName in the event object, but the java223 action context doesn't receive a source value.
(i.e. inputs.get("source") is null)

and missest lastStateUpdate and lastStateChange.

Yes, objects from eventinfo package are lacking details. I will try to complete them.

I thought until now that @InjectBinding is only handling data from ScriptEngine.put()/.scopeValues(), but when handling SimpleRule.execute() there is no preceeding scriptEngine.put(). So @InjectBinding does not do the initialization based on scriptEngine.put().

Honestly, I don't really know who puts the data and when.
I take them from the script context with this :

context.getBindings(ScriptContext.GLOBAL_SCOPE);
context.getBindings(ScriptContext.ENGINE_SCOPE);

And for rule action, I simply take them from the inputs (which is a Map<String, ?>) passed as parameters to the SimpleRule.execute.

Is itemName taken from the org.openhab.core.automation.events.TimerEvent.getPayload(), from inputs.get('source'), or from where? I have not looked in the BindingInjector implementation,but I have the feeling this syntax with fullstop in named= is not documented.

The fullstop is a 'traversal' syntaxic sugar I added.
event.itemName means input.get("event").itemName (java reflection behing scene)
You are right, documentation for the InjectBinding annotation is lacking. I added it.

Can this eventinfo/ItemStateChange annotation be used on a Java-method, which is part of SimpleRule, but has no @rule annotation and does not inherit from the Java223Script class?

No, a SimpleRule designed by yourself is some java code who lives completely independently of the java223 bundle. No custom injection can occur, as openHAB calls the execute method directly.

I think it is mixed: an ItemStateUpdateTrigger supplies data for ItemStateChange handler, the parameter probably should be eventinfo.ItemStateUpdate.

Oops, indeed. Fixed.

Can as parameter values be used execute(eventinfo.ItemStateChange d1, eventinfo.ItemStateUpdate d2) , so one extra parameter? It makes sense, but I think this cannot work.

No it probably won't work, because ItemStateChange and ItemStateUpdate have different mandatory parameters. The issue here is "mandatory". No individual trigger can provide those different parameters to the two EventInfo class at the same time.
For this double trigger, we should use the generic parameter Map<String, ?> bindings.
Out of this, it should work. Injection in method parameters are not limited to the first one.
You can even design your own EventInfo class: as soon as it is defined as a library of the automation/lib/ directory, it will be a candidate for auto injection.

I suggest removing all not needed @InjectBindings, so that it is clear what they do and do not do, unless there is some performance impact having explict @InjectBinding present, which impact is not yet described.

Which ones are not needed ?
Do you talk about those with no apparent configuration ? Their purpose are to activate their mandatory aspect.
I think the 'fail fast' functionality it allows is important. For example:

  • A user using a wrong EventInfo object as parameter will be quickly notified of the error.
  • if openHAB changes the name of the input, it will force the rule to fail immediately instead of depending on how the user has coded his rule.

@dilyanpalauzov
Copy link
Author

So for core.ItemStateChangeTrigger the fields are … and source

but the java223 action context doesn't receive a source value. (i.e. inputs.get("source") is null)

That is correct, I meant module instead of source.

I suggest removing all not needed @InjectBindings, so that it is clear what they do and do not do, unless there is some performance impact having explict @InjectBinding present, which impact is not yet described.

Which ones are not needed ? Do you talk about those with no apparent configuration? Their purpose are to activate their mandatory aspect.
I think the 'fail fast' functionality it allows is important. For example:

  • A user using a wrong EventInfo object as parameter will be quickly notified of the error.
  • if openHAB changes the name of the input, it will force the rule to fail immediately instead of depending on how the user has coded his rule.

I mean them.

# grep -ri @InjectBinding[^\(]
helper/generated/Java223Script.java:    protected @InjectBinding Map<String, Object> bindings;
helper/generated/Java223Script.java:    protected @InjectBinding ItemRegistry ir;
helper/generated/Java223Script.java:    protected @InjectBinding ItemRegistry itemRegistry;
helper/generated/Java223Script.java:    protected @InjectBinding LifecycleTracker lifecycleTracker;
helper/generated/Java223Script.java:    protected @InjectBinding Map<String, State> items;
helper/generated/Java223Script.java:    protected @InjectBinding RuleRegistry rules;
helper/generated/Java223Script.java:    protected @InjectBinding ScriptBusEvent events;
helper/generated/Java223Script.java:    protected @InjectBinding ScriptThingActions actions;
helper/generated/Java223Script.java:    protected @InjectBinding ThingRegistry things;
helper/generated/Java223Script.java:    protected @InjectBinding ScriptExtensionManagerWrapper scriptExtension;
helper/generated/Java223Script.java:    protected @InjectBinding ScriptExtensionManagerWrapper se;
helper/generated/Java223Script.java:    protected @InjectBinding RuleManager ruleManager;
helper/generated/Java223Script.java:    protected @InjectBinding ThingManager thingManager;
helper/generated/Java223Script.java:    protected @InjectBinding MetadataRegistry metadataRegistry;
helper/generated/Java223Script.java:    protected @InjectBinding Items _items;
helper/generated/Java223Script.java:    protected @InjectBinding Actions _actions;
helper/generated/Java223Script.java:    protected @InjectBinding Things _things;

Currently the only thing which is guaranteed to fail, once openHAB cuts instances from the presets, or removes services (RuleManager) is Java223Script and classes, which derive from it, and code generated by ScriptWrapping strategy. So all the Java223Script extra magic, which might not be used by the user (in case of wrapped one-line scripts) will stop functioning, e.g. because the unused protected @InjectBinding MetadataRegistry metadataRegistry; stopped resolving.

@dilyanpalauzov
Copy link
Author

Can this eventinfo/ItemStateChange annotation be used on a Java-method, which is part of SimpleRule, but has no @rule annotation and does not inherit from the Java223Script class?

No, a SimpleRule designed by yourself is some java code who lives completely independently of the java223 bundle. No custom injection can occur, as openHAB calls the execute method directly.

eventinfo/ItemStateChange annotation is ambiguous. It could mean ItemStateChangeTrigger annotation, or ItemStateChange parameter type (no annotation). I meant the second and my reading is that the parameter type ItemStateChange cannot be used in actions, which are from non-Java223Script derived classes.

I do not understand the above. In UI-based rules, where Java223 is only in charge for the action, openHAB calls the execute method directly. How can then the eventinfo.ItemStateChange() parameter type be used?

@dalgwen
Copy link
Owner

dalgwen commented Oct 9, 2025

eventinfo/ItemStateChange annotation is ambiguous

I agree, I wasn't satisfied either when I wrote them.
Now I'm thinking about putting EventInfo as a suffix on every class extending EventInfo. If you think it's not good, please tell me so.

is only in charge for the action, openHAB calls the execute method directly. How can then the eventinfo.ItemStateChange() parameter type be used?

When the action part of a rule is a script, openHAB asks the jsr223 bundle to run the script and passes the full context along (i.e. full context = "standard" binding value + event info, all in the same context map).
The bundle then does whatever it wants. In our case, with full control, the java223 does this:

  • instantiate the class defined in the script
  • run all runnable parts

The openHAB context injection will occur at those moments:

  • as parameter in the constructor
  • as field in the class (after instantiation)
  • as parameter of the runnable methods

For each of those cases, the bundle will try its best to chose what value to pass, and where, by using as a hint:

  • name of the parameter or field (if it matches a key from the binding context map)
  • the type of the parameter (if it matches a library already registered in the lib directory, it will understand that it has to instantiate it and populate its field) <--- this is the case of all EventInfo object. If you pass them as parameters, or as fields, they will be magically filled.

We can override this behaviour by using the InjectBinding annotation.

On the contrary, when you define a SimpleRule by yourself and registers it to the RuleManager, the java223 bundle is NOT called when the action is executed. The execute method is directly called, with the raw binding map as a parameter.

Java223Script extra magic, which might not be used by the user (in case of wrapped one-line scripts) will stop functioning

The wrapped one-line script has in fact the same fields as the Java223Script base class (It is basically a copy). Injection occurs exactly the same.
(The only thing different is that the parsing method for detecting rules inside is not executed)

@dilyanpalauzov
Copy link
Author

eventinfo/ItemStateChange annotation is ambiguous

I agree, I wasn't satisfied either when I wrote them.
Now I'm thinking about putting EventInfo as a suffix on every class extending EventInfo. If you think it's not good, please tell me so.

It is not good. Every class extending EventInfo is in package helper.rules.eventinfo, so to be used, one has anyway to spell eventinfo - in one way or another - less or more explicit - before it. It will be clear enough, if the examples in README.md are adjusted to either spell out the needed import, or use the fully qualified name, when using public void myRule(ItemStateUpdate inputs).

Besides, this examples in README, appearing twice itemRegistry.get("myitem").send(OnOffType.ON); will not work, as first itemRegistry.get("myitem") has to be cast to an Item (which has the send() method). One of the examples can be cast to an Item, the other can use instead itemRegistry.getItem("myitem").

Java223Script extra magic, which might not be used by the user (in case of wrapped one-line scripts) will stop functioning

The wrapped one line script has effectively the same fields as the Java223 script (It is basically a copy). Injection occurs exactly the same.

That is what I am saying. When for some reason the service MetadataRegistry disappears, then this line

protected @InjectBinding MetadataRegistry metadataRegistry;

will make sure, that the one-liner is not running anymore (cannot be recompiled anymore), even if metadataRegistry is not used by the one-liner.

Here a more practical example with disappearing services: when I ordinary shut down openhab, Java223 logs sometimes in openhab.log:

2025-10-09 11:50:33.846 [INFO ] [el.core.internal.ModelRepositoryImpl] - Unloading DSL model 'r3.items'
2025-10-09 11:50:40.142 [DEBUG] [ernal.codegeneration.SourceGenerator] - Generating actions
2025-10-09 11:50:40.143 [WARN ] [ernal.codegeneration.SourceGenerator] - Cannot create helper class file in library directory
java.io.IOException: Cannot generate Actions
        at org.openhab.automation.java223.internal.codegeneration.SourceGenerator$InternalGenerator.generate(SourceGenerator.java:457) ~[?:?]
        at org.openhab.automation.java223.internal.codegeneration.SourceGenerator.lambda$3(SourceGenerator.java:159) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:317) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.lang.Thread.run(Thread.java:1583) [?:?]
Caused by: java.lang.IllegalStateException: BundleContext is no longer valid org.openhab.automation.java223_5.0.1 [249]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.checkValid(BundleContextImpl.java:1031) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.getServiceReferences(BundleContextImpl.java:567) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.getServiceReferences(BundleContextImpl.java:1068) ~[org.eclipse.osgi-3.18.0.jar:?]
        at org.openhab.automation.java223.internal.codegeneration.SourceGenerator.internalGenerateActions(SourceGenerator.java:214) ~[?:?]
        at org.openhab.automation.java223.internal.codegeneration.SourceGenerator$InternalGenerator.generate(SourceGenerator.java:453) ~[?:?]
        ... 7 more

Probably because the reference to the service ceased to exist.

| mandatory | If set to true (which is the default), the injection will fail if the variable is not found.

What means will fail? I suggest instead either to say that there will be a run-time exception, or that the value will be left null?

openHAB also prevents several executions of the same rule at the same time.
This means, for example, that a script defined as the 'Action' part of a GUI rule cannot run concurrently, even if triggered by another rule at the same moment (The second one will fail).

openHAB prevents several executions of the same script at the same time.
This is also the case for transformations/profile (the second transformation will wait for the first to finish). This can be an issue, especially if your script takes some non-negligible time to execute.

This is not so correct. runNow() calling rules executes the called rules, irrespective of whether the rules are runnig currently, that is - in parallel. The nuances are discussed at openhab/openhab-docs#2573 . I have to add, that I wrote that text based on what others suggested, not on doing experiments myself.

openhab/openhab-docs#2570 states already, that one and the same transformation cannot be executed at the same time, so this information can be removed from java223/README.md. I suggest you contribute to the discussion at openhab/openhab-docs#2573 about what can and cannot run in parallel. Then this information will be relevant for all OH Automation add-ons and can be removed from java223/README.md . As a side effect, what is correct statement on this parallelism in openHAB, or a false statement, will be reviewed by more people.

@dalgwen
Copy link
Owner

dalgwen commented Oct 13, 2025

if the examples in README.md are adjusted to either spell

Besides, this examples in README [...] will not work

Ok, done

java.lang.IllegalStateException: BundleContext is no longer valid
Probably because the reference to the service ceased to exist.

Another subject: it would be interesting to know it openHAB is stopping to prevent (broken) code generation.

will make sure, that the one-liner is not running anymore (cannot be recompiled anymore), even if metadataRegistry is not used by the one-liner.

OK, I think that means we are not on the same page on this, because I think failing is good here.
If the service disappears, then something is fishy (and probably on a larger scale), and so instead of executing something with a potential unknown behaviour, I'd like the script to fail altogether.
This is an interesting topic, and I think it would be nice to talk about it with other maintainers when I will make a PR later on.

What means will fail? I suggest instead either to say that there will be a run-time exception, or that the value will be left null?

If there is no InjectBinding annotation, then the value will be left null.
If there is a InjectBinding annotation and mandatory is not set to false, then the error will be logged and the script won't execute.
I added this info in the README.

Then this information will be relevant for all OH Automation add-ons and can be removed from java223/README.md

Excellent ! May I say "good riddance" ? 😂 Global documentation is a way better location for this 👍

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.

2 participants