[Transformation JavaScript] Getting an error after moving to openHAB 2.5.6~S147-1 (Build #147)

Moved from stable 2.5.5 to snapshot openHAB 2.5.6~S147-1 (Build #147).
I am now getting an error from the ( installed) javascript transformation.
The script used to work before.
The error shows whenever I try to show the sitemap subpage that uses the script.

Did I miss a change?

JScript:

(function(i) {
    if(isNaN(i)) return "NA";
    var days = Math.floor(i/1440)
    var hours = Math.floor((i-days*1440)/60);
    var min = Math.floor((i-hours*60-days*1440)/1);
    var pad = "00";
    return days+ " Tag(e) " +hours+" Std "+min+" Min";
})(input)

Error observed:

2020-06-18 19:07:08.287 [WARN ] [org.eclipse.jetty.server.HttpChannel] - /basicui/app 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.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.transform(ItemUIRegistryImpl.java:537) ~[?:?]

at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getLabel(ItemUIRegistryImpl.java:449) ~[?:?]

at org.openhab.ui.basic.internal.render.AbstractWidgetRenderer.preprocessSnippet(AbstractWidgetRenderer.java:123) ~[?:?]

at org.openhab.ui.basic.internal.render.TextRenderer.renderWidget(TextRenderer.java:61) ~[?:?]

at org.openhab.ui.basic.internal.render.PageRenderer.renderWidget(PageRenderer.java:194) ~[?:?]

at org.openhab.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:160) ~[?:?]

at org.openhab.ui.basic.internal.render.PageRenderer.processPage(PageRenderer.java:124) ~[?:?]

at org.openhab.ui.basic.internal.servlet.WebAppServlet.service(WebAppServlet.java:209) ~[?:?]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[bundleFile:3.1.0]

at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544) ~[bundleFile:9.4.20.v20190813]

at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) ~[bundleFile:?]

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307) ~[bundleFile:9.4.20.v20190813]

at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) ~[bundleFile:?]

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[bundleFile:9.4.20.v20190813]

at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) ~[bundleFile:?]

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.Server.handle(Server.java:494) ~[bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) [bundleFile:9.4.20.v20190813]

at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) [bundleFile:9.4.20.v20190813]

at java.lang.Thread.run(Thread.java:748) [?:1.8.0_252]

Maybe related:

1 Like

I’m having the same issue. I have several items with JS transforms that each create the error:

2020-06-21 22:13:47.930 [ERROR] [b.core.service.AbstractActiveService] - 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:?]

I comments out all but one of the items:

String Flights "Flights: [%s]" (Dump1090) { http="<[http://garage:8080/data/aircraft.json:10000:JS(flights.js)]" }

To try and rule out javascript errors I’ve changed the transform to simple return a string:

(function (i) {
        return 'hi'
})(input)

This started after upgrading to 2.5.6 from 2.5.5.today. This is an openhabian install on Debian Buster.

My http items using REGEX or XSLT seem to work fine.

I’m having the same issue after upgrading to 2.5.6. I also have several items with JS transformations. Each of them is ending up in error. Here is an example of a JS Transformation.

// computes nicely formatted duration from given minutes
(function(i){ 

	var d = Math.floor(i / (24 * 60));
	var h = Math.floor((i / 60) - (24 * d));
	var m = Math.round(i - 60 * (24 * d + h));
	var result = '';

	// days
	if (d > 0) { 
		result = result + d;
		if (d == 1) {
			result = d + " Tag";
		} else {
			result = d + " Tage";
		}
	}

	// hours
	if (h > 0) {
		if (result != '') {
			result = result + ', ';
		}
		result = result + h;
		if (h == 1) {
			result = result + ' Stunde';
		} else {
			result = result + ' Stunden';
		}
	}
	
	// minutes
	if (m > 0) {
		if (result != '') {
			result = result + ', ';
		}
		result = result + m;
		if (m == 1) {
			result = result + ' Minute';
		} else {
			result = result + ' Minuten';
		}
	}

	return result;
})(input)

The only thing that worked for me is to change every item from “XYZ [JS(transformation.js):%s]” to “XYZ [%s]” and restart the openhab service.

As already noticed from taing, the other transformation services work fine.

I hope the JS Transformation service will be fixed soon.

Also the REST API seems to be broken. Lot of errors in Visual Studio Code with the openhab extension.

The issue on GitHub is closed and reports are out that it is working on 2.5.7 snapshot #152.
Read here

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.