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

[JS transformation] NPE in JavaScriptEngineManager when getting Javascript Engine #7880

Closed
dk8pn opened this issue Jun 9, 2020 · 11 comments · Fixed by openhab/openhab-distro#1117
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@dk8pn
Copy link

dk8pn commented Jun 9, 2020

Issue: JavaScript transformation

Expected Behavior

Using 2.5.5 snapshot #111, everything worked out normal. JS transform was used to add an offset to a watermeter counter in order to create the grand total water consumption in qubic meters.

Current Behavior

After upgrade to 2.5.6 snapshot #131 or newer, JS transformation from sitemap item label doesn't longer work out. Sitemap line item (see below) needs to be disabled to make other group members working again. Other transforms defined vs paperUI items definition still work out.

Steps to Reproduce (for Bugs)

Sitemap line item:
Text item=WassermesserSensor_1_GasEnergyCounter label="Wasserzähler Stand [JS(wasseruhr_offset.js):%s]" icon="watermeter"

JavaSript file:
(function(i) {
var scale = " m3"; //workaround for display of the unit m3
var total = parseFloat(i) + 623.162; //sum of the water meter offset 623,162 m3 and the HomeMatic counter value
var new_total = total.toFixed(3); //limits the digits after the dot to 3
return new_total.toString().replace('.', ',') + scale; //replaces dot by comma and adds the unit m3
})(input)

Your Environment

Windows10, openHAB2.5.5, snapshot #111

@dk8pn dk8pn added the bug An unexpected problem or unintended behavior of an add-on label Jun 9, 2020
@dk8pn dk8pn changed the title JS transformation from sitemap item label stopped working using latest 2.5.6 snapshots [JS transformation] from sitemap item label stopped working using latest 2.5.6 snapshots Jun 10, 2020
@Rossko57
Copy link
Contributor

Linked discussion, with error log
https://community.openhab.org/t/js-transformation-stopped-working-after-upgrade-to-2-5-6-snapshot-131/99705/3

Would you report the Java version you use, please? I think OH uses the javascript from host Java.

@clinique
Copy link
Contributor

Ubuntu 19.04
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (Zulu 8.46.0.19-CA-linux64) (build 1.8.0_252-b14)
OpenJDK 64-Bit Server VM (Zulu 8.46.0.19-CA-linux64) (build 25.252-b14, mixed mode)

@clinique
Copy link
Contributor

I suspect it comes from the main issue, if I send :

http://192.168.0.199:8080/rest/items?recursive=false

I get no answer from the server, an NPE being raised :

Caused by: java.lang.NullPointerException
	at org.openhab.transform.javascript.internal.JavaScriptEngineManager.getScript(JavaScriptEngineManager.java:68) ~[?:?]
	at org.openhab.transform.javascript.internal.JavaScriptTransformationService.transform(JavaScriptTransformationService.java:74) ~[?:?]
	at org.eclipse.smarthome.core.transform.TransformationHelper.transform(TransformationHelper.java:125) ~[?:?]
	at org.eclipse.smarthome.core.transform.TransformationHelper.transform(TransformationHelper.java:100) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTOMapper.considerTransformation(EnrichedItemDTOMapper.java:124) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTOMapper.map(EnrichedItemDTOMapper.java:67) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTOMapper.map(EnrichedItemDTOMapper.java:61) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.internal.item.ItemResource.lambda$0(ItemResource.java:230) ~[?:?]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_252]
	at java.util.HashMap$KeySpliterator.tryAdvance(HashMap.java:1577) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:295) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:207) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:170) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:301) ~[?:1.8.0_252]
	at java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681) ~[?:1.8.0_252]
	at org.eclipse.smarthome.io.rest.Stream2JSONInputStream.fillBuffer(Stream2JSONInputStream.java:93) ~[?:?]
	at org.eclipse.smarthome.io.rest.Stream2JSONInputStream.read(Stream2JSONInputStream.java:69) ~[?:?]
	at java.io.InputStream.read(InputStream.java:179) ~[?:1.8.0_252]
	at java.io.InputStream.read(InputStream.java:101) ~[?:1.8.0_252]
	at org.glassfish.jersey.message.internal.ReaderWriter.writeTo(ReaderWriter.java:115) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider.writeTo(AbstractMessageReaderWriterProvider.java:79) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:105) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:60) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[bundleFile:?]
	at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) ~[?:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[bundleFile:?]
	at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) ~[?:?]
	... 53 more

@Rossko57
Copy link
Contributor

JavaScriptTransformationService

Yup, that failure blows up the Item REST fetch

@dk8pn
Copy link
Author

dk8pn commented Jun 10, 2020

Linked discussion, with error log
https://community.openhab.org/t/js-transformation-stopped-working-after-upgrade-to-2-5-6-snapshot-131/99705/3

Would you report the Java version you use, please? I think OH uses the javascript from host Java.

Have Windows10, 64bit, openHAB2.5.5 snapshot #111 (working), openHAB2.5.6 snapshot #131 (not working, has the issue), JavaScript 1.8.0_251

@jpg0
Copy link
Contributor

jpg0 commented Jun 19, 2020

Whilst I don't use Windows, or 2.5.6 (yet) I have seen this error lots as part of implementing a newer JS engine. When loading the newer JS engine it 'takes over' the existing one (Nashorn) and leaves it in a broken state. This will cause the exception here.
This probably isn't much use to any non-devs, but hopefully it's a useful data point!

@elisman
Copy link

elisman commented Jun 21, 2020

I suspect it comes from the main issue, if I send :

http://192.168.0.199:8080/rest/items?recursive=false

I get no answer from the server, an NPE being raised :

Caused by: java.lang.NullPointerException
	at org.openhab.transform.javascript.internal.JavaScriptEngineManager.getScript(JavaScriptEngineManager.java:68) ~[?:?]
	at org.openhab.transform.javascript.internal.JavaScriptTransformationService.transform(JavaScriptTransformationService.java:74) ~[?:?]
	at org.eclipse.smarthome.core.transform.TransformationHelper.transform(TransformationHelper.java:125) ~[?:?]
	at org.eclipse.smarthome.core.transform.TransformationHelper.transform(TransformationHelper.java:100) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTOMapper.considerTransformation(EnrichedItemDTOMapper.java:124) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTOMapper.map(EnrichedItemDTOMapper.java:67) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.item.EnrichedItemDTOMapper.map(EnrichedItemDTOMapper.java:61) ~[?:?]
	at org.eclipse.smarthome.io.rest.core.internal.item.ItemResource.lambda$0(ItemResource.java:230) ~[?:?]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_252]
	at java.util.HashMap$KeySpliterator.tryAdvance(HashMap.java:1577) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:295) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:207) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:170) ~[?:1.8.0_252]
	at java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:301) ~[?:1.8.0_252]
	at java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681) ~[?:1.8.0_252]
	at org.eclipse.smarthome.io.rest.Stream2JSONInputStream.fillBuffer(Stream2JSONInputStream.java:93) ~[?:?]
	at org.eclipse.smarthome.io.rest.Stream2JSONInputStream.read(Stream2JSONInputStream.java:69) ~[?:?]
	at java.io.InputStream.read(InputStream.java:179) ~[?:1.8.0_252]
	at java.io.InputStream.read(InputStream.java:101) ~[?:1.8.0_252]
	at org.glassfish.jersey.message.internal.ReaderWriter.writeTo(ReaderWriter.java:115) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider.writeTo(AbstractMessageReaderWriterProvider.java:79) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:105) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.InputStreamProvider.writeTo(InputStreamProvider.java:60) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) ~[bundleFile:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[bundleFile:?]
	at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) ~[?:?]
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) ~[bundleFile:?]
	at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) ~[?:?]
	... 53 more

I have the same issue. I am running the stable version openHAB 2.5.6-1 on Ubuntu 18.04.4 and OpenJDK 1.8.0_252. When I try to view items in BasicUI, the NPE is thrown on the server. Frames are not being displayed. 😞

@kaikreuzer
Copy link
Member

@openhab/add-ons-maintainers Does anyone of you have an idea what could have broken this code?
Looking at https://github.com/openhab/openhab-addons/commits/2.5.x/bundles/org.openhab.transform.javascript, the only change in 2.5.6 was applying spotless on the pom.xml - I cannot see any other change.
What change could cause the ScriptEngineManager to not find the engine for javascript anymore...?

@kaikreuzer kaikreuzer changed the title [JS transformation] from sitemap item label stopped working using latest 2.5.6 snapshots [JS transformation] NPE in ScriptEngineManager when getting Javascript Engine Jun 21, 2020
@kaikreuzer kaikreuzer changed the title [JS transformation] NPE in ScriptEngineManager when getting Javascript Engine [JS transformation] NPE in JavaScriptEngineManager when getting Javascript Engine Jun 21, 2020
@Rossko57
Copy link
Contributor

Note that some users reporting some javascript transformations work, some don't. Context for the transformation (binding, label, etc.) appears irrelevant. No-one has yet reported JSR223 javascript rules as a roblem, but that usage might be rare.

@helmar74
Copy link

helmar74 commented Jun 22, 2020

After Upgrading to 2.5.6 same issue here.

Only using Java Script transform in the HTTP Binding for a cached URL
(config in /etc/openhab2/services/http.cfg):
(Ical.url=http://REMOTEURL.ics)

The .ics is than transformed thru Java Script:
String i_STRING { http="<[Ical:3600000:JS(transform.js)]" }

I get an "transform error" in the log every second:

 - Error while executing background thread HTTP Refresh Service
java.lang.NullPointerException: null
        at org.openhab.transform.javascript.internal.JavaScriptEngineManager.getScript(JavaScriptEngineManager.java:68) ~[?:?]
        at org.openhab.transform.javascript.internal.JavaScriptTransformationService.transform(JavaScriptTransformationService.java
:74) ~[?:?]
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:69) ~[
bundleFile:?]
        at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:218) ~[?:?]
        at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile
:?]
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]

So I stopped the HTTP Binding, to get rid of these log entries.

Regards

Helmar

@obrador
Copy link

obrador commented Jun 22, 2020

Same issue also here after upgrade to 2.5.6

Debian stretch with official openhab2 repositories.

wborn added a commit to wborn/openhab-distro that referenced this issue Jun 22, 2020
They cause issues when used with Java 8.

Fixes openhab/openhab-addons#7880

Signed-off-by: Wouter Born <[email protected]>
kaikreuzer pushed a commit to openhab/openhab-distro that referenced this issue Jun 22, 2020
They cause issues when used with Java 8.

Fixes openhab/openhab-addons#7880

Signed-off-by: Wouter Born <[email protected]>
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
Development

Successfully merging a pull request may close this issue.

8 participants