Javascript transform - Arrow functions break things (OpenHabian 2.3.0)

In creating a new javascript transform for some JSON I discovered using arrow functions can create a real problem. The error was seen in syslog not in the openhab log: “Exception in thread “HTTP Refresh Service” java.lang.AssertionError: Failed generating bytecode for :3”

The code in question:

(function (i) {
var tmp = JSON.parse(i)
return tmp.timelines.filter( x => x.onstage == true ).map(elem => elem.name).join(’ + ')||“No timeline”;
})(input)

The modified working version:

(function (i) {
var tmp = JSON.parse(i)
return tmp.timelines.filter( function(x) { return x.onstage == true } ).map( function (elem) { return elem.name } ).join(’ + ')||“No timeline”;
})(input)

There is no functional difference just a bit prettier with the arrow functions…

After the exception all http binding refresh stops until openhab is restarted.

I suppose that since the JavaScript is running embedded inside of Java that perhaps the Java embedded version of JavaScript doesn’t support arrow functions. It is weird that the exception kills the whole HTTP binding though. That shouldn’t happen and an issue probably should be filed in the Eclipse Smarthome Repo.

I don’t know if there is anything they can do about adding the arrow function but at least they can keep use of it from killing the whole binding.