diff --git a/CHANGELOG.md b/CHANGELOG.md index 2732cb851..64e050563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ + * Fix `Loader.load()` not properly force loading all inherited target classes ([issue #1](https://github.com/bytedeco/javacpp/issues/1)) + ### April 28, 2014 version 0.8 * Move from Google Code to GitHub as main source code repository * Place build-time classes in the `org.bytedeco.javacpp.tools` package and bring out static nested classes, in an effort to avoid conflicts and ease development diff --git a/pom.xml b/pom.xml index 1c85bd988..5c73a59bf 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.bytedeco javacpp - 0.8 + 0.8-1-SNAPSHOT maven-plugin JavaCPP diff --git a/src/main/java/org/bytedeco/javacpp/ClassProperties.java b/src/main/java/org/bytedeco/javacpp/ClassProperties.java index 189cc18e2..e83ec3c60 100644 --- a/src/main/java/org/bytedeco/javacpp/ClassProperties.java +++ b/src/main/java/org/bytedeco/javacpp/ClassProperties.java @@ -126,6 +126,7 @@ public void load(Class cls, boolean inherit) { classList.addFirst(c); while (!c.isAnnotationPresent(org.bytedeco.javacpp.annotation.Properties.class) && !c.isAnnotationPresent(Platform.class) && c.getSuperclass() != Object.class) { + // accumulate superclasses to process native methods from those as well classList.addFirst(c = c.getSuperclass()); } if (effectiveClasses == null) { diff --git a/src/main/java/org/bytedeco/javacpp/Loader.java b/src/main/java/org/bytedeco/javacpp/Loader.java index 59e14f6e9..16cbafdba 100644 --- a/src/main/java/org/bytedeco/javacpp/Loader.java +++ b/src/main/java/org/bytedeco/javacpp/Loader.java @@ -368,18 +368,29 @@ public static String load(Class cls) { // Find the top enclosing class, to match the library filename cls = getEnclosingClass(cls); + ClassProperties p = loadProperties(cls, loadProperties(), true); - // Force initialization of the class in case it needs it - try { - cls = Class.forName(cls.getName(), true, cls.getClassLoader()); - } catch (ClassNotFoundException ex) { - Error e = new NoClassDefFoundError(ex.toString()); - e.initCause(ex); - throw e; + // Force initialization of all the target classes in case they need it + LinkedList targets = p.get("target"); + if (targets.isEmpty()) { + if (p.getInheritedClasses() != null) { + for (Class c : p.getInheritedClasses()) { + targets.add(c.getName()); + } + } + targets.add(cls.getName()); + } + for (String s : targets) { + try { + Class.forName(s, true, cls.getClassLoader()); + } catch (ClassNotFoundException ex) { + Error e = new NoClassDefFoundError(ex.toString()); + e.initCause(ex); + throw e; + } } // Preload native libraries desired by our class - ClassProperties p = loadProperties(cls, loadProperties(), true); LinkedList preloads = new LinkedList(); preloads.addAll(p.get("platform.preload")); preloads.addAll(p.get("platform.link"));