From 97b61ea3297e04e64aab1e1a4ec50202e9f86fff Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Mon, 16 Aug 2021 11:09:47 +0200 Subject: 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 --- ridljar/com/sun/star/lib/util/NativeLibraryLoader.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ridljar/com/sun/star') diff --git a/ridljar/com/sun/star/lib/util/NativeLibraryLoader.java b/ridljar/com/sun/star/lib/util/NativeLibraryLoader.java index eb5c6af34e90..d255a71ea5d1 100644 --- a/ridljar/com/sun/star/lib/util/NativeLibraryLoader.java +++ b/ridljar/com/sun/star/lib/util/NativeLibraryLoader.java @@ -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.

*/ 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. * -- cgit