ClassNotFoundException after restarting debug session

Hi all!

I would like some help building my first binding.
In my livingroom I have a rooted Toon (a dutch thermostat) which I would like to integrate in my home automation. There have been previous attempts by others to implement the binding but currently there is no binding available as far as I know.

I’ve used the public repository from Daan Meijer as a starting point and tried to get it to work in my current set-up of OpenHAB 3.2.0. I believe Daan already started a topic to get this binding up and running but I was only able to find his source code.

After setting up the Eclipse IDE with the 3.2.0 tagged versions of the openhab-addons and openhab-distro I was able to debug an OpenHAB instance and could start working on the rootedtoon binding. Altough my very limited experience in JAVA I managed to get the binding to work and even added some additional functionality to communicate with ZWave devices through the Toon.

The problem I now run into each time is the error messages I get once I start the debug session.
When I completely clear the org.openhab.core.thing.Thing.json and start a new debug session all works without issues. But whenever I restart the debug session with the data in
org.openhab.core.thing.Thing.json kept in place from the previous debug session the binding no longer works.

During development I just cleared the org.openhab.core.thing.Thing.json file each time but now I would like to put a version in my live OpenHAB environment (by copying the .jar file to the OpenHAB addons folder) And the same error shows up here as well and I don’t know how to prevent it.

The exact error does not really give me a clear hint because the function ThingHandler.initialize() seems to work fine if the things file is initially cleared. The only thing I can think of is an issue in correctly clearing/disposing parts I generate with the binding.

Please let me know what additional information I can provide to help understand the issue, I can imagine the current description is too limited.

[ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.rootedtoon.internal.RootedToonHandler@4372749d': java.lang.ClassNotFoundException
java.lang.RuntimeException: java.lang.ClassNotFoundException

Does it show a stack trace or only the error you’ve shown? Looking at the repository you linked too, it seems it’s not compilable (git conflicts) and also contains references to ‘old’ packages, e.g. org.eclipse.smarthome.core.types. Did you fix those?

Hi Hilbrand,

It shows a bit more:

[ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.rootedtoon.internal.RootedToonHandler@4372749d': java.lang.ClassNotFoundException
java.lang.RuntimeException: java.lang.ClassNotFoundException
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:50) ~[?:?]
	at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:55) ~[?:?]
	at org.openhab.binding.rootedtoon.internal.client.ToonClient.<init>(ToonClient.java:87) ~[?:?]
	at org.openhab.binding.rootedtoon.internal.RootedToonHandler.initialize(RootedToonHandler.java:147) ~[?:?]
	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:834) [?:?]
Caused by: java.lang.ClassNotFoundException
	at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:120) ~[?:?]
	at javax.ws.rs.client.ClientFinder.find(ClientFinder.java:96) ~[?:?]
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:44) ~[?:?]
	... 13 more
Caused by: java.lang.InstantiationException
	at jdk.internal.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]
	at java.lang.Class.newInstance(Class.java:584) ~[?:?]
	at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:116) ~[?:?]
	at javax.ws.rs.client.ClientFinder.find(ClientFinder.java:96) ~[?:?]
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:44) ~[?:?]
	... 13 more
14:49:43.454 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'rootedtoon:toonbridge:f21e92347e': java.lang.ClassNotFoundException
java.lang.RuntimeException: java.lang.ClassNotFoundException
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:50) ~[?:?]
	at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:55) ~[?:?]
	at org.openhab.binding.rootedtoon.internal.client.ToonClient.<init>(ToonClient.java:87) ~[?:?]
	at org.openhab.binding.rootedtoon.internal.RootedToonHandler.initialize(RootedToonHandler.java:147) ~[?:?]
	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:834) [?:?]
Caused by: java.lang.ClassNotFoundException
	at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:120) ~[?:?]
	at javax.ws.rs.client.ClientFinder.find(ClientFinder.java:96) ~[?:?]
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:44) ~[?:?]
	... 13 more
Caused by: java.lang.InstantiationException
	at jdk.internal.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]
	at java.lang.Class.newInstance(Class.java:584) ~[?:?]
	at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:116) ~[?:?]
	at javax.ws.rs.client.ClientFinder.find(ClientFinder.java:96) ~[?:?]
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:44) ~[?:?]
	... 13 more

And yes I think I fixed the git conflicts as far as I can see. But maybe I missed something as I’m completely new to all this. I already have been able to run an older version of the progress I made succesfully in my life OpenHAB environment.

Double check clasloader which is being used to instantiate client code. It might be that you have a context class loader which is floating between cases.

I’m afraid I don’t know where or how I can check this. I don’t really understand the way (parts of) the binding are started through the class loaders.

Try adding wrapper in RootedToonHandler#initialize with something like that:

try {
    // ... 
} catch (ClassNotFoundException e) {
    System.out.println(Thread.currentThread().getName());
    System.out.println(Thread.currentThread().getContextClassLoader());
}
```

Thanks for the support.
Unfortunately my Java knowledge is not sufficient to even get this wrapper to work. :upside_down_face:

I’m not sure if in the Eclipse IDE develop environment the userdata like the org.openhab.core.thing.Thing.json file can be left alone while perfoming multiple debug sessions after eachother? Perhaps it is always required to clean these files?

In the meantime I was able to solve a configuration issue in the live environment which caused the binding to crash (I was not providing “http://” to the bridge URL configuration).

Ok some small progress.
I’ve been debugging the code together with a friend and we could follow the classloader to where it starts adding the client for our binding; ToonClient.

I did not succeed in using the wrapper but I can now pinpoint the error down to the function “newInstance()” which also shows it is deprecated?!

Do I maybe have forgotten to update a part/library of the binding to the JAVA11?

Debugging shows the path up to the error as:
RootedToonHandler.initialize() →
ToonClient →
ClientBuilder.newClient() →
ClientBuilder.newBuilder() →
ClientFinder.find() →
ClientFinder.newInstance() →
spiClass.newInstance()

Which will throw an InstantiationException

And is referring to “javax.ws.rs.client.ClientBuilder”

Does anyone have any hints here?

ClientBuilder is part of standard jaxrs library which works fine in most of the cases. However it might have different behavior depending on which thread and classloader backs loading. Please look closer at the classloader used by client builder but also at class which is not found. Try finding its name.
If you get these two we can look where it comes from and how to make it available through binding classloader (which is most likely used).