Class org.openhab.core.thing.internal.ThingImpl cannot be cast to class org.openhab.core.thing.Bridge

I’m trying to update the Ring binding so that the account Thing is now a Bridge. The Ring binding was written by someone else back in the 2.5 days and I’ve inherited it to try to get it merged into 4.x. I’ve looked at several other bindings and I can’t tell where I’ve missed. I’m getting the exception below…

2023-07-24 15:06:22.754 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while calling thing handler factory 'org.openhab.binding.ring.internal.RingHandlerFactory@4656342d': class org.openhab.core.thing.internal.ThingImpl cannot be cast to class org.openhab.core.thing.Bridge (org.openhab.core.thing.internal.ThingImpl and org.openhab.core.thing.Bridge are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @657324aa)
java.lang.ClassCastException: class org.openhab.core.thing.internal.ThingImpl cannot be cast to class org.openhab.core.thing.Bridge (org.openhab.core.thing.internal.ThingImpl and org.openhab.core.thing.Bridge are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @657324aa)
        at org.openhab.binding.ring.internal.RingHandlerFactory.createHandler(RingHandlerFactory.java:91) ~[?:?]
        at org.openhab.core.thing.binding.BaseThingHandlerFactory.registerHandler(BaseThingHandlerFactory.java:129) ~[?:?]
        at org.openhab.core.thing.internal.ThingManagerImpl.doRegisterHandler(ThingManagerImpl.java:530) ~[?:?]
        at org.openhab.core.thing.internal.ThingManagerImpl.registerHandler(ThingManagerImpl.java:511) ~[?:?]
        at org.openhab.core.thing.internal.ThingManagerImpl.registerAndInitializeHandler(ThingManagerImpl.java:926) ~[?:?]
        at org.openhab.core.thing.internal.ThingManagerImpl.checkMissingPrerequisites(ThingManagerImpl.java:1122) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

Code is at…

I’m crosseyed now on where I have missed something. Any help is greatly apprecaited.

There should be an extra check before class cast i.e. thing instanceof Bridge, only then it is safe to cast this given thing to Bridge.
See line https://github.com/morph166955/openhab-addons/blob/ring/bundles/org.openhab.binding.ring/src/main/java/org/openhab/binding/ring/internal/RingHandlerFactory.java#L91C43-L91C43 - it does assume that thing is a bridge based on its type, however this might depend on user configuration and other aspects, i.e. XML declaration which can run out of sync and be thing-type instead of bridge-type, which seemed to be a case for you. :slight_smile:

Anyhow, see you are making progress!

It looks like I had some leftover thing configuration in my json. I added the thing instanceof Bridge and put a log warning if it’s not a bridge. Thanks!

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