Skip to content

Commit

Permalink
* Fix Loader.load() not properly force loading all inherited targe…
Browse files Browse the repository at this point in the history
…t classes (issue #1)
  • Loading branch information
saudet committed May 3, 2014
1 parent 5e0ed47 commit 282926e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>0.8</version>
<version>0.8-1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>JavaCPP</name>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/bytedeco/javacpp/ClassProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/org/bytedeco/javacpp/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> preloads = new LinkedList<String>();
preloads.addAll(p.get("platform.preload"));
preloads.addAll(p.get("platform.link"));
Expand Down

0 comments on commit 282926e

Please sign in to comment.