ridljar: check that UnoClassLoader is used for NativeLibraryLoader

The native libraries are local to class loaders, so
System.load("java_uno.so") will fail with any other class loader.

Change-Id: Ifa3b1b8dfef07b64828943654e28ff1f0fb5a494
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120527
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
This commit is contained in:
Michael Stahl 2021-08-16 11:09:47 +02:00
parent 71ebb55b4e
commit 97b61ea329

View file

@ -21,6 +21,7 @@ package com.sun.star.lib.util;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import com.sun.star.lib.unoloader.UnoClassLoader;
/**
* Helper functions to locate and load native files.
@ -35,6 +36,14 @@ import java.net.URLClassLoader;
* algorithm.</p>
*/
public final class NativeLibraryLoader {
static {
// if it's some other class loader, then resolving the symbol
// Java_com_sun_star_bridges_jni_1uno_JNI_1proxy_dispatch_1call in
// java_uno will not work and result in UnsatisfiedLinkError
if (!(NativeLibraryLoader.class.getClassLoader() instanceof com.sun.star.lib.unoloader.UnoClassLoader)) {
System.err.println("warning: com.sun.star.lib.util.NativeLibraryLoader must be loaded by com.sun.star.lib.unoloader.UnoClassLoader for java_uno bridge to work (not a problem if this is using Java remote bridge or unit test)");
}
}
/**
* Load a system library, using a given class loader to locate the library.
*