openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.58k forks source link

[tibber] NPE reading config from server #14267

Closed seime closed 1 year ago

seime commented 1 year ago

Found this in my log; likely caused by problems on Tibber side. Binding recovered automatically, but maybe error handling could be further improved.

WDYT @kjoglum ?

Running openHAB 3.4.1

2023-01-23 10:54:04.334 [WARN ] [ibber.internal.handler.TibberHandler] - Unable to establish websocket session - Reattempting connection on next refresh
2023-01-23 10:54:05.935 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.tibber.internal.handler.TibberHandler@1b
4da88': null
java.lang.NullPointerException: null
        at org.openhab.binding.tibber.internal.handler.TibberHandler.getTibberParameters(TibberHandler.java:142) ~[?:?]
        at org.openhab.binding.tibber.internal.handler.TibberHandler.initialize(TibberHandler.java:97) ~[?:?]
        at jdk.internal.reflect.GeneratedMethodAccessor72.invoke(Unknown Source) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
        at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]
2023-01-23 10:54:05.942 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'tibber:tibberapi:account': null
java.lang.NullPointerException: null
        at org.openhab.binding.tibber.internal.handler.TibberHandler.getTibberParameters(TibberHandler.java:142) ~[?:?]
        at org.openhab.binding.tibber.internal.handler.TibberHandler.initialize(TibberHandler.java:97) ~[?:?]
        at jdk.internal.reflect.GeneratedMethodAccessor72.invoke(Unknown Source) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
        at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]
2023-01-23 10:54:34.620 [WARN ] [ibber.internal.handler.TibberHandler] - Websocket Client Stop Exception: java.lang.InterruptedException
lsiepel commented 1 year ago

Just had a quick look at the code. The NPE is thrown due to the return JSON form the tibber server does not have the expected format combined with the code not checking if the JSON properties exists.

Just made a PR. Would be nice if you can test it. 4.0.0 JAR: https://1drv.ms/u/s!AnMcxmvEeupwjqVJMTcLNSI-WqtArA?e=PzGWNC