NPE on empty query, influxdb (2.5.12)


Seems I always get a NPE when querying for persistance data where there is none to get, ie.
I have a “gPersistInfluxChange* : strategy = everyChange,everyHour,everyDay” policy on an item.
If I query that item with averageSince:

if (pe.averageSince(ir.getItem("W_Electricthingy"),, "influxdb") > DecimalType(50)):
    la.logDebug("DEBUG", "TESTING123: ITS TRUE")
    la.logDebug("DEBUG", "TESTING123: ITS FALSE")

It always throws an NPE:
2021-03-31 13:21:19.626 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/’: java.lang.NullPointerException: java.lang.NullPointerException in at line number 57

But it works just fine if there is actual data/measurements to retrieve…

Shouldn’t this return a false/null value instead?

OH: 2.5.12
Influx: 1.8.4

Err, I think it does … the error is to then try to use null > number in your if().
You’ll need to test result === null before trying to use it.

1 Like

You’re right, but I only made it work comparing it to “None”, like this: if (result == None)