Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsscripting] Unable to import classes from org.openhab.core #11222

Closed
ssalonen opened this issue Sep 8, 2021 · 7 comments · Fixed by #11400
Closed

[jsscripting] Unable to import classes from org.openhab.core #11222

ssalonen opened this issue Sep 8, 2021 · 7 comments · Fixed by #11400
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@ssalonen
Copy link
Contributor

ssalonen commented Sep 8, 2021

After installing jsscripting addon (using workaround steps documented in #11219), I cannot seem to import classes from org.openhab.core, although other java imports seem to work (e.g. org.slf4j.LoggerFactory)

Expected Behavior

Java.type("org.openhab.core.items.Metadata") should work successfully with jsscripting bundle installed, similar how it works with the default javascript engine.

Current Behavior

Error is raised when executing script

09:38:32.712 [ERROR] [ab.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: Access to host class org.openhab.core.items.Metadata is not allowed or does not exist.
	at <js>.:anonymous(<eval>:5) ~[?:?]
	at <js>.:program(<eval>:1) ~[?:?]
	at org.graalvm.polyglot.Context.eval(Context.java:345) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:379) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:356) ~[?:?]
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1183) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1035) ~[?:?]

Steps to Reproduce (for Bugs)

  1. Follow steps in [jsscripting] jsscripting automation bundle installation issues #11219 to install the addon. After addon installation and openHAB restart, use the following script to get the error:
(function (context) {
  var log = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + context.ruleUID)
  
  log.info( Java.type("org.openhab.core.items.Metadata") )
})(this);

Context

Trying to migrate to ES6 in rules/scripts. This is blocking such transition as, combined with #11221, openHAB functionality is completely unavailable from rules/script with jsscripting addon installed.

Your Environment

I can reproduce with 3.1.0 release and 3.2.0 M2.

Linux  5.13.13-200.fc34.x86_64 #1 SMP Thu Aug 26 17:06:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
@ssalonen ssalonen added the bug An unexpected problem or unintended behavior of an add-on label Sep 8, 2021
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/all-my-ecmascript-scripts-stopped-working-throwing-exceptions/125341/10

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/usage-of-new-ecma2021-automation-scripting-graalvm/122724/24

@LukasA83
Copy link
Contributor

I'm having the same issue. The workaround identifed is no longer working:
jpg0/oh-config#2 (comment)

I'm unable to get services via the bundlecontext.

Any ideas @jpg0 ?

@ssalonen
Copy link
Contributor Author

ssalonen commented Sep 21, 2021

@LukasA83 please note that this particular issue I have reported is separate from ohj & ohj-support .

Here we are talking issues experienced just with the jsscripting addon and the nonworking import with openhab packages/classes.

Are the issues you refer to related to these 3rd party plugins (ohj, ohj-support)? If so, it might be better to file the issue to their respective issue handlers?

However, I would be curious to learn if the OSGI service lookup of openHAB services also becomes non-working when jsscripting addon is installed.

@jpg0
Copy link
Contributor

jpg0 commented Sep 21, 2021

It's interesting that the import of the first (sl4j) class succeeds, yet it fails to import the openHAB class.

Currently the bundle is marked as DynamicImport-Package: * so it should dynamically look up the class fine.

@LukasA83
Copy link
Contributor

LukasA83 commented Sep 22, 2021

ok, I believe I found another workaround. Still strange, that the scriptExtension is not available. Any hint?

digitaldan added a commit to digitaldan/openhab-addons that referenced this issue Oct 17, 2021
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
digitaldan added a commit to digitaldan/openhab-addons that referenced this issue Oct 17, 2021
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
cweitkamp pushed a commit that referenced this issue Oct 19, 2021
…urrent class. (#11400)

Fixes #11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
frederictobiasc pushed a commit to frederictobiasc/openhab-addons that referenced this issue Oct 26, 2021
…urrent class. (openhab#11400)

Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
dschoepel pushed a commit to dschoepel/openhab-addons that referenced this issue Nov 9, 2021
…urrent class. (openhab#11400)

Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dave J Schoepel <dave@theschoepels.com>
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/usage-of-new-ecma2021-automation-scripting-graalvm/122724/25

kaikreuzer pushed a commit that referenced this issue Dec 13, 2021
Fixes #11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this issue Dec 30, 2021
…urrent class. (openhab#11400)

Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this issue Dec 30, 2021
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
mischmidt83 pushed a commit to mischmidt83/openhab-addons that referenced this issue Jan 9, 2022
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Michael Schmidt <mi.schmidt.83@gmail.com>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this issue Jan 28, 2022
…urrent class. (openhab#11400)

Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this issue Jan 28, 2022
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this issue May 5, 2022
…urrent class. (openhab#11400)

Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this issue May 5, 2022
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
andan67 pushed a commit to andan67/openhab-addons that referenced this issue Nov 6, 2022
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
andrasU pushed a commit to andrasU/openhab-addons that referenced this issue Nov 12, 2022
Fixes openhab#11222

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
4 participants