Giter VIP home page Giter VIP logo

Comments (2)

wardev avatar wardev commented on July 21, 2024

Upon further investigation it seems that the problem is two fold.

First the code at [1] does not check the return value of FindClass before using it in another function call at [2], which causes the segfault. Specifically, FindClass will return 0 if it doesn't find the class and GetStaticFieldID will segfault if the class is null.

As a Java developer, I would expect that if a class cannot be found then a ClassNotFoundException will be thrown.

Second the code at [1] does not use the correct ClassLoader. Quoting from [3], "FindClass locates the class loader associated with the current native method; that is, the class loader of the class that declared the native method." If " there is no current native method or its associated class loader [then] in that case, the result of ClassLoader.getSystemClassLoader is used." Looking at the back trace there is no Java frames that FindClass can retrieve the ClassLoader from, so it will use the system ClassLoader, which does not contain the requested class.

As a Java developer, I would expect that if a class needs to be loaded to service a request then the ClassLoader of the class making the request will be used, or the ClassLoader of the callback.

As a Java developer, I expect the system ClassLoader will never be used.

Finally, one more request. Please include debugging symbols in your releases. Then it will be much easier to find the bugs in the native code as I won't have to disassemble it first.

[1]

jclass clazz = jenv->FindClass("gov/nasa/gsfc/gmsec/api/Connection$ConnectionEvent");

[2]

jfieldID jField = jenv->GetStaticFieldID(clazz, eventString, "Lgov/nasa/gsfc/gmsec/api/Connection$ConnectionEvent;");

[3] https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#FindClass

from gmsec_api.

wardev avatar wardev commented on July 21, 2024

Looking through the code a bit more, it seems that [4] has the right idea - to initialize all classes when the JNI interface is initialized. Then there will be Java frame on the stack, so FindClass will use that ClassLoader. It seems the call to FindClass should be moved form Jenv to Cache. And any other calls to load GMSEC API Java classes should be done in Cache as well so they are loaded when the JNI interface is initialized.

[4]

Cache::getCache().initialize(jenv);

from gmsec_api.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.