mercredi 29 juin 2016

Class.forName() is not working with a particular class

I am trying to load with java reflection a bunch of classes. Everything seems working fine (I am handling the exception if the class is not found).

However there is a particular class that is raising another exception that is not thrown by call to the Class.forname() but by an internal method and so I cannot even catch it.

Here is my code:

try {
     URL url = Class.forName(qualifiednameOfTheClass);
} catch (ClassNotFoundException ex) {
     // ok class not found can be handled
} catch (Exception e){
     // catch every other exception just to try to get the strange exception
}

So with this code everything is working, I am using it on lots of classes and it's working (sometimes it finds it sometimes it doesn't).

However there is one case that is not working properly and I cannot understand why. If qualifiednameOfTheClass = sun.security.krb5.SCDynamicStoreConfig my code is raising an exception:

Exception in thread "mythread-1" java.lang.UnsatisfiedLinkError: no osx in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1088) at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:67) at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:47) at java.security.AccessController.doPrivileged(Native Method) at sun.security.krb5.SCDynamicStoreConfig.(SCDynamicStoreConfig.java:39) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:190) at com.myclass.getJARFromClassForName(JavaId.java:510) at com.myclass.getJARUrl(Id.java:550) at com.myclass.collectInformation(Graph.java:366) at com.myclass.createNode(Graph.java:166) at com.myclass.Graph.(Graph.java:143) at com.myclass2.run(myclass2.java:246) at java.lang.Thread.run(Thread.java:745)

So as you can see in the error we have this strange exception that cannot be catched even with a generic catch like in my code and I cannot understand why it has been raised and what actually is this osx library (I am on linux)

EDIT: The only thing that I found is this link http://ift.tt/29brtgr but is in german and so I read it with google translate and I don't know if I got it right but is basically saying that the classes listed there cannot be reproduced with Class.forname() itself.

Is it true? Is there a reason why this cannot be loaded with reflection or am I doing something wrong?





Aucun commentaire:

Enregistrer un commentaire