How do I fix "handler already disposed" warnings in the binding I'm developing

I get this warning all the time and I’m not sure where the error is in my binding that’s causing it. I’d really appreciate any pointers on what to look for to fix it.

Developing this binding (for WiZ lighting: is my very first foray into Java - most of the programming I’ve done has been for Arduino/cpp.

Since you didn’t specify the error you’re seeing, it’s difficult to help you.

Is it similar to this one?

tried updating channel [x] although the handler was already disposed.

I’m sorry, yes, lots of those errors about updating various channels and occasionally about updating the thing status.

I usually see the errors on booting up (OpenHABian on RPi 3b) or stopping the OpenHAB service, but occasionally random other times.

Don’t allow channel updates to propagate after the handler has been disposed.

Well, yes, quite obviously.

What I don’t understand is how it would even be possible for a function that is a member of the handler object to even exist after the handler object is gone let alone do something. Maybe I’m totally misunderstanding the handler life cycle (zero Java experience). I thought the handler was created in memory when the thing was first created (or the system boots) and persisted until the thing was removed or the system shuts down. Is the handler disposed/recreated between jobs scheduled with fixed delay?

I did find that I’d somehow lost my dispose method leaving a hanging polling job. Oops. Fixing that dramatically cut down the errors, but I’m still getting some.

1 Like

I’ve noticed when developing a binding that when I put my freshly built jar in the addons-folder and start OH, the old version somehow lingers in the cache and is started first. Then it is stopped and the new version is loaded. If there are any remaining scheduled jobs that aren’t properly cancelled though, these continue to run, trying to update the thing. Can it be something like that you’re experiencing? Make sure you use the dispose() method in your handler to clean everything up.

For reference, I’m working on Windows using intellij. I haven’t managed to automate the process of starting OH, so I have to do it manually after copying the add-on jar.

1 Like

Other classes (e.g. the modbus binding) check if the handler has been disposed before doing work:

if (hasConfigurationError() || disposed) {

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.