Should uninstalling and reinstalling a bundle containing a native library work without restarting the JVM?

Let’s say we have a bundle that contains a native library.

  • I install that bundle and the native library gets loaded by the JVM.
  • Now I uninstall the bundle.
  • Finally, I install the same bundle again.

Should that work fine?

I am asking because trying this, there is a message like this:

Caused by: java.lang.UnsatisfiedLinkError: Native Library X.so already loaded in another classloader

Or is should it be expected that after uninstalling a bundle with a native library, a restart of the JVM should be performed?

P.S.: I am aware this is not really a BND question ,but this is the best place I know to ask this.

Yes, that can work. However, there are lots of pitfalls. Many shortcuts people take as well as errors in the code can easily cause leaks. They are usually not very visible in Java, the gc takes care. However, with native code you absolutely must get your life cycle in order.

The message sounds like the old bundle is still active. That can happen because you have memory leaks so the class loader is not gc’ed or you never refreshed the bundle with the native library. After an update, it is mandatory to refresh the framework.

Native code is not for the faint of heart. Native code in a dynamic environment is masterclass level software :slight_smile: I know, have been hurt lots of times.

1 Like