Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javacpp does not export package required by presets #483

Closed
reckart opened this issue May 28, 2021 · 6 comments · Fixed by #508
Closed

Javacpp does not export package required by presets #483

reckart opened this issue May 28, 2021 · 6 comments · Fixed by #508
Assignees
Labels

Comments

@reckart
Copy link
Contributor

reckart commented May 28, 2021

Presets such as the openblas preset in recent versions inherit from org.bytedeco.javacpp.presets.javacpp:

@Properties(inherit = javacpp.class, global = "org.bytedeco.openblas.global.openblas_nolapack", value = {
...
public class openblas_nolapack implements LoadEnabled, InfoMapper {

In an OSGI context, this leads to a ClassNotFoundException being thrown as part of loading the class annotations:

java.lang.ClassNotFoundException: org.bytedeco.javacpp.presets.javacpp cannot be found by <MY-BUNDLE>

I only discover the above exception by putting a breakpoint in the constructor of the TypeNotPresentExceptionProxy...
Otherwise, here is a stack trace showing the annotation loading:

Thread [AsyncThread-1] (Suspended (breakpoint at line 41 in TypeNotPresentExceptionProxy))	
	owns: Nd4j  (id=180)	
	owns: ConcurrentHashMap$ReservationNode<K,V>  (id=181)	
	TypeNotPresentExceptionProxy.<init>(String, Throwable) line: 41	
	AnnotationParser.parseClassValue(ByteBuffer, ConstantPool, Class<?>) line: 429	
	AnnotationParser.parseClassArray(int, ByteBuffer, ConstantPool, Class<?>) line: 724	
	AnnotationParser.parseArray(Class<?>, ByteBuffer, ConstantPool, Class<?>) line: 531	
	AnnotationParser.parseMemberValue(Class<?>, ByteBuffer, ConstantPool, Class<?>) line: 355	
	AnnotationParser.parseAnnotation2(ByteBuffer, ConstantPool, Class<?>, boolean, Class<Annotation>[]) line: 286	
	AnnotationParser.parseAnnotations2(byte[], ConstantPool, Class<?>, Class<Annotation>[]) line: 120	
	AnnotationParser.parseAnnotations(byte[], ConstantPool, Class<?>) line: 72	
	Class<T>.createAnnotationData(int) line: 3521	
	Class<T>.annotationData() line: 3510	
	Class<T>.createAnnotationData(int) line: 3526	
	Class<T>.annotationData() line: 3510	
	Class<T>.createAnnotationData(int) line: 3526	
	Class<T>.annotationData() line: 3510	
	Class<T>.getAnnotation(Class<A>) line: 3415	
	Loader.checkPlatform(Class<?>, Properties) line: 1010	
	Loader.load(Class, Properties, boolean) line: 1161	
	Loader.load() line: 1123	
	Nd4jCpu.<clinit>() line: 13	
	Class<T>.forName0(String, boolean, ClassLoader, Class<?>) line: not available [native method]	
	Class<T>.forName(String) line: 264	
	NativeOpsHolder.<init>() line: 85	
	NativeOpsHolder.<clinit>() line: 35	
	NativeOpExecutioner.<init>() line: 91	
	NativeConstructorAccessorImpl.newInstance0(Constructor<?>, Object[]) line: not available [native method]	
	NativeConstructorAccessorImpl.newInstance(Object[]) line: 62	
	DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 45	
	Constructor<T>.newInstance(Object...) line: 423	
	Class<T>.newInstance() line: 442	
	Nd4j.initWithBackend(Nd4jBackend) line: 5215	
	Nd4j.initContext() line: 5129	
	Nd4j.<clinit>() line: 226	
...

As far as I can tell is because the org.bytedeco.javacpp.presets is actually not exported from the JavaCPP JAR:

Export-Package: org.bytedeco.javacpp;uses:="org.bytedeco.javacpp.annot
 ation";version="1.5.5",org.bytedeco.javacpp.annotation;version="1.5.5
 ",org.bytedeco.javacpp.indexer;uses:="org.bytedeco.javacpp";version="
 1.5.5",org.bytedeco.javacpp.tools;uses:="javax.management";version="1
 .5.5"

Unfortunately, the 1.5.2 JavaCPP also hast some issue with OSGi that I currently do not remember. So I have to combine JavaCPP 1.5.4 with openblas 0.3.7-1.5.2 because the latter is the last version that comes without the inherit = javacpp.class... but of course then I get warnings telling me that it is probably a bad idea to mix JavaCPP 1.5.4 with a lib that was build against the older 1.5.2 version.

@reckart
Copy link
Contributor Author

reckart commented May 28, 2021

For anybody running into the same issue, here is what I did to fix it for me:

I copied the org.bytedeco.javacpp.presets.javacpp class into <MY-BUNDLE> so that loading the annotation on the openblas class doesn't crash. Pretty hacky, but it seems to do the trick.

Would still be great if JavaCPP could be changed to export that package in an OSGI context.

@saudet
Copy link
Member

saudet commented May 29, 2021 via email

@saudet
Copy link
Member

saudet commented May 29, 2021

/cc @timothyjward

@timothyjward
Copy link
Contributor

If this package is part of the public API (which it seems to be from the big report) it needs a package-info.java and Export Annotation to tell the bnd-maven-plugin to export it.
There are already examples in the code, e.g. https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/package-info.java

@saudet saudet removed the help wanted label Jun 3, 2021
@HannesWell
Copy link

I had the same problem using javacpp and CPython with an Eclipse/OSGi application and came up with the same solution.
PR #490 provided to solve this issue, fixed it in my case. So first of all thanks for that.

However I wonder if the org.bytedeco.javacpp.presets package should also be exported in the java9/module-info.java?
I don't use the JPMS actively, so I cannot say if it is required or not. I just found it when searching for a solution of my problem and thought it could be required.

@saudet
Copy link
Member

saudet commented Jul 16, 2021

However I wonder if the org.bytedeco.javacpp.presets package should also be exported in the java9/module-info.java?
I don't use the JPMS actively, so I cannot say if it is required or not. I just found it when searching for a solution of my problem and thought it could be required.

Most likely, yes. Please send a pull request if you can! Thanks

/cc @HGuillemet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants