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] fix null pointer exception when sending command to a device that is offline #12347

Merged
merged 2 commits into from
Feb 26, 2022

Conversation

robnielsen
Copy link
Contributor

This fixes the following error when a Tradfri device is offline:

2022-02-22 09:43:07.970 [DEBUG] [internal.handler.TradfriThingHandler] - Sending payload: {"3312":[{"5850":0}],"3":null}
2022-02-22 09:43:07.981 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.tradfri.internal.handler.TradfriPlugHandler@e7b2d8': null
java.lang.NullPointerException: null
        at org.openhab.binding.tradfri.internal.handler.TradfriThingHandler.set(TradfriThingHandler.java:139) ~[?:?]
        at org.openhab.binding.tradfri.internal.handler.TradfriPlugHandler.setState(TradfriPlugHandler.java:58) ~[?:?]
        at org.openhab.binding.tradfri.internal.handler.TradfriPlugHandler.handleCommand(TradfriPlugHandler.java:73) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        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.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [bundleFile:?]
        at com.sun.proxy.$Proxy489.handleCommand(Unknown Source) [?:?]
        at org.openhab.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:80) [bundleFile:?]
        at org.openhab.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:48) [bundleFile:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        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) [?:?]

It now logs:

2022-02-22 09:58:52.159 [DEBUG] [internal.handler.TradfriThingHandler] - coapClient is null!

…at is offline

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
@lolodomo lolodomo added the bug An unexpected problem or unintended behavior of an add-on label Feb 22, 2022
@lolodomo
Copy link
Contributor

lolodomo commented Feb 22, 2022

Please also consider potential NPE in method setStatus and in methods handleCommand in all handlers when handling REFRESH command.

@cweitkamp
Copy link
Contributor

At best we should change the annotation of the property coapClient from @NinNullByDefault({}) to @Nullable to find all possible places for an NPE.

@lolodomo
Copy link
Contributor

At best we should change the annotation of the property coapClient from @NinNullByDefault({}) to @Nullable to find all possible places for an NPE.

I fully agree.

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
@robnielsen
Copy link
Contributor Author

At best we should change the annotation of the property coapClient from @NinNullByDefault({}) to @nullable to find all possible places for an NPE.

done

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lolodomo lolodomo merged commit 9fd87f5 into openhab:main Feb 26, 2022
@lolodomo lolodomo added this to the 3.3 milestone Feb 26, 2022
@robnielsen robnielsen deleted the tradfri branch February 26, 2022 15:24
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Apr 27, 2022
… that is offline (openhab#12347)

* [tradfri] fix null pointer exception when sending command to thing that is offline
* [tradfri] changed coapClient from @NinNullByDefault({}) to @nullable

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
… that is offline (openhab#12347)

* [tradfri] fix null pointer exception when sending command to thing that is offline
* [tradfri] changed coapClient from @NinNullByDefault({}) to @nullable

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
… that is offline (openhab#12347)

* [tradfri] fix null pointer exception when sending command to thing that is offline
* [tradfri] changed coapClient from @NinNullByDefault({}) to @nullable

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Feb 23, 2023
… that is offline (openhab#12347)

* [tradfri] fix null pointer exception when sending command to thing that is offline
* [tradfri] changed coapClient from @NinNullByDefault({}) to @nullable

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
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 this pull request may close these issues.

3 participants