Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tradfri] NPE if gateway is unreachable #9628

Closed
t2000 opened this issue Jan 1, 2021 · 0 comments · Fixed by #9629
Closed

[tradfri] NPE if gateway is unreachable #9628

t2000 opened this issue Jan 1, 2021 · 0 comments · Fixed by #9629
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@t2000
Copy link
Contributor

t2000 commented Jan 1, 2021

In case the IKEA gateway is unreachable the binding runs into an NPE:

2021-01-01 15:31:32.243 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.tradfri.internal.handler.TradfriControllerHandler@6f16b0c4': null
java.lang.NullPointerException: null
        at org.eclipse.californium.core.CoapClient.setEndpoint(CoapClient.java:354) ~[?:?]
        at org.openhab.binding.tradfri.internal.handler.TradfriThingHandler.initialize(TradfriThingHandler.java:73) ~[?:?]
        at jdk.internal.reflect.GeneratedMethodAccessor58.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:834) [?:?]

The reason being that handler.getEndpoint() returns null here:

TradfriGatewayHandler handler = (TradfriGatewayHandler) tradfriGateway.getHandler();
String uriString = handler.getGatewayURI() + "/" + id;
try {
URI uri = new URI(uriString);
coapClient = new TradfriCoapClient(uri);
coapClient.setEndpoint(handler.getEndpoint());

I noticed that the gateway handler (bridge) does not have an endpoint if it is OFFLINE.

All happened during the initialization, so after the bridge goes OFFLINE the initialization of the handlers is triggered and then runs into the NPE.

2021-01-01 15:31:32.228 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'tradfri:gateway:ikeagw' changed from INITIALIZING to OFFLINE (COMMUNICATION_ERROR): No response from gateway. Might be due to an invalid security code.
2021-01-01 15:31:32.233 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'tradfri:0830:ikeagw:ikeaRemote' changed from UNINITIALIZED (BRIDGE_UNINITIALIZED) to INITIALIZING
2021-01-01 15:31:32.235 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'tradfri:0210:ikeagw:ikeaColor' changed from UNINITIALIZED (BRIDGE_UNINITIALIZED) to INITIALIZING
2021-01-01 15:31:32.261 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'tradfri:0830:ikeagw:ikeaRemote' changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR)
2021-01-01 15:31:32.261 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'tradfri:0210:ikeagw:ikeaColor' changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR)

I will provide a PR that sets the coapEndpoint only if the bridge is ONLINE.

@t2000 t2000 added the bug An unexpected problem or unintended behavior of an add-on label Jan 1, 2021
t2000 added a commit to t2000/openhab2-addons that referenced this issue Jan 1, 2021
kaikreuzer pushed a commit that referenced this issue Jan 1, 2021
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this issue Nov 7, 2021
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this issue May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant