Skip to content

Commit 2f7c956

Browse files
committed
* Make sure Loader.load() also initializes classes that are passed explicitly
1 parent 18aec22 commit 2f7c956

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
* Make sure `Loader.load()` also initializes classes that are passed explicitly
23
* Fix `Loader.createLibraryLink()` incorrectly truncating library versions when there is one before and another after the suffix
34
* Iterate extensions of libraries or executables on `Loader.load()` in reverse to be consistent with properties overriding
45
* Allow prefixing library names with `:` to have `Loader` consider them as filenames with prefix and suffix already included

src/main/java/org/bytedeco/javacpp/Loader.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ public static String load() {
948948
return load(getCallerClass(2), loadProperties(), Loader.pathsFirst);
949949
}
950950
/**
951-
* Loads native libraries associated with the {@link Class} of the caller.
951+
* Loads native libraries associated with the {@link Class} of the caller and initializes it.
952952
*
953953
* @param pathsFirst search the paths first before bundled resources
954954
* @return {@code load(getCallerClass(2), loadProperties(), pathsFirst) }
@@ -964,9 +964,9 @@ public static String load(Class cls) {
964964
return load(cls, loadProperties(), Loader.pathsFirst);
965965
}
966966
/**
967-
* Loads native libraries associated with the given {@link Class}.
967+
* Loads native libraries associated with the given {@link Class} and initializes it.
968968
*
969-
* @param cls the Class to get native library information from
969+
* @param cls the Class to get native library information from and to initialize
970970
* @param properties the platform Properties to inherit
971971
* @param pathsFirst search the paths first before bundled resources
972972
* @return the full path to the main file loaded, or the library name if unknown
@@ -977,6 +977,8 @@ public static String load(Class cls) {
977977
* @see #loadLibrary(URL[], String)
978978
*/
979979
public static String load(Class cls, Properties properties, boolean pathsFirst) {
980+
Class classToLoad = cls;
981+
980982
if (!isLoadLibraries() || cls == null) {
981983
return null;
982984
}
@@ -999,6 +1001,12 @@ public static String load(Class cls, Properties properties, boolean pathsFirst)
9991001
}
10001002
targets.add(cls.getName());
10011003
}
1004+
1005+
// Make sure that we also initialize the class that was passed explicitly
1006+
if (!targets.contains(classToLoad.getName())) {
1007+
targets.add(classToLoad.getName());
1008+
}
1009+
10021010
for (String s : targets) {
10031011
try {
10041012
if (logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)