Persistence invocation results in NPE (ESH bug?)

I am trying to compute the average of a temperature in a rule using this code:

    var avgTemp = Temperature.averageSince(now.minusDays(1))

which gives the following message in the log:

2018-09-21 08:08:10.054 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule ‘Initialize irrigation’: null

The Temperature item has values in the database (as I can see on a grafana graph), but the current state is NULL due to a communication problem with weatherunderground.

When invoked in a timer I do get a stack trace:

2018-09-21 08:24:37.645 [ERROR] [org.quartz.core.JobRunShell         ] - Job DEFAULT.2018-09-21T08:24:37.579+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
  logInfo(<XStringLiteralImpl>,<XBinaryOperationImplCustom>)
  logInfo(<XStringLiteralImpl>,<XBinaryOperationImplCustom>)
  var avgTemp
  logInfo(<XStringLiteralImpl>,<XStringLiteralImpl>)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@1c9f7b7
} ] threw an unhandled Exception:
java.lang.NullPointerException: null
        at org.eclipse.smarthome.model.persistence.extensions.PersistenceExtensions.averageSince(PersistenceExtensions.java:455) [124:org.eclipse.smarthome.model.persistence:0.10.0.201808011124]
        at org.eclipse.smarthome.model.persistence.extensions.PersistenceExtensions.averageSince(PersistenceExtensions.java:407) [124:org.eclipse.smarthome.model.persistence:0.10.0.201808011124]

Even though the current state is NULL, i would nevertheless expect an average value. This looks like a bug in ESH to me, or have I overlooked something?

After I edited my wunderground local weather thing, it reconnected and populated the Temperature item with a value and the rule works.

Hi Volker,

thanks for reporting. I have been trying to tackle down this NPE in my own system for some time. And finally found a solution for it. Fix has been submitted:

So it wasn’t me doing something stupid for a change. Nice. Thanks for fixing the bug.

Just as a side node, it would make finding these kind of problems easier if the rule engine would log exceptions somewhere instead of just printing messages like the one above.