ClassloadingUtil.class.getClassLoader() returns null

170 views
Skip to first unread message

jda...@redhat.com

unread,
Apr 10, 2017, 12:03:51 PM4/10/17
to Java™ Pathfinder
I noticed that the .getClassLoader() method in JPF is currently implemented to return null. My program relies on this.

What could be done about it, besides changing my program?

Nastaran Shafiei

unread,
Apr 10, 2017, 3:05:50 PM4/10/17
to java-pa...@googlegroups.com
Are you referring to the getClassLoader method in Class? This method is not set to return null - it captures similar behavior to its counterpart from Java standard libraries.

Nastaran

On Apr 10, 2017, at 9:03 AM, jda...@redhat.com wrote:

I noticed that the .getClassLoader() method in JPF is currently implemented to return null. My program relies on this.

What could be done about it, besides changing my program?

--

---
You received this message because you are subscribed to the Google Groups "Java™ Pathfinder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-pathfind...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jda...@redhat.com

unread,
Apr 11, 2017, 5:56:36 PM4/11/17
to Java™ Pathfinder
On Monday, April 10, 2017 at 9:05:50 PM UTC+2, nastaran wrote:
Are you referring to the getClassLoader method in Class? This method is not set to return null - it captures similar behavior to its counterpart from Java standard libraries.

Nastaran

You are correct, I made a mistake when reading the stacktrace

The SUT code in question is

    public static Object newInstanceFromClassLoader(final String className) {

ClassLoader loader = ClassloadingUtil.class.getClassLoader();
try {
Class<?> clazz = loader.loadClass(className);
return clazz.newInstance();
} catch (Throwable t) {
t.printStackTrace();
if (t instanceof InstantiationException) {
System.out.println(INSTANTIATION_EXCEPTION_MESSAGE);
}
loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
throw new RuntimeException("No local context classloader", t);
....


I got the exception "No local context classloader" exception from the last line in the listing.

#getClassLoader is completely fine, the problem is #getContextClassLoader which is programmed to always return null in JPF

 public class Thread implements Runnable {
 
...
     
public ClassLoader getContextClassLoader () {
         
// <NSY>
         
return null;
     
}


 

(what does NSY stand for?) 


I am not sure if my SUT actually needs #getContextClassLoader for its normal operations. Currently, I am inclined to believe I just had a bad luck to pick a JUnit test which needed this. When I moved to different test, this problem did not arise.

Anyways, my current exception is (with jpf-nhandler)

* DELEGATING Unhandled Native -> sun.management.OperatingSystemImpl.initialize
[SEVERE] JPF exception, terminating: exception in native method sun.management.OperatingSystemImpl.initialize
java.lang.UnsatisfiedLinkError: sun.management.OperatingSystemImpl.initialize()V
        at sun.management.OperatingSystemImpl.initialize(Native Method)
        at sun.management.OperatingSystemImpl.<clinit>(OperatingSystemImpl.java:54)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at OTF_JPF_sun_management_OperatingSystemImpl.initialize____V(OTF_JPF_sun_management_OperatingSystemImpl.class)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at gov.nasa.jpf.vm.NativeMethodInfo.executeNative(NativeMethodInfo.java:125)
        at gov.nasa.jpf.jvm.bytecode.EXECUTENATIVE.execute(EXECUTENATIVE.java:73)
        at gov.nasa.jpf.vm.ThreadInfo.executeInstruction(ThreadInfo.java:1908)
        at gov.nasa.jpf.vm.ThreadInfo.executeTransition(ThreadInfo.java:1859)
        at gov.nasa.jpf.vm.SystemState.executeNextTransition(SystemState.java:765)
        at gov.nasa.jpf.vm.VM.forward(VM.java:1722)
        at gov.nasa.jpf.search.Search.forward(Search.java:579)
        at gov.nasa.jpf.search.DFSearch.search(DFSearch.java:79)
        at gov.nasa.jpf.JPF.run(JPF.java:613)
        at gov.nasa.jpf.JPF.start(JPF.java:189)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at gov.nasa.jpf.tool.Run.call(Run.java:80)
        at gov.nasa.jpf.tool.RunJPF.main(RunJPF.java:116)
---------------------- JPF error stack trace ---------------------
gov.nasa.jpf.JPFNativePeerException: exception in native method sun.management.OperatingSystemImpl.initialize
        at gov.nasa.jpf.vm.NativeMethodInfo.executeNative(NativeMethodInfo.java:186)
        at gov.nasa.jpf.jvm.bytecode.EXECUTENATIVE.execute(EXECUTENATIVE.java:73)
        at gov.nasa.jpf.vm.ThreadInfo.executeInstruction(ThreadInfo.java:1908)
        at gov.nasa.jpf.vm.ThreadInfo.executeTransition(ThreadInfo.java:1859)
        at gov.nasa.jpf.vm.SystemState.executeNextTransition(SystemState.java:765)
        at gov.nasa.jpf.vm.VM.forward(VM.java:1722)
        at gov.nasa.jpf.search.Search.forward(Search.java:579)
        at gov.nasa.jpf.search.DFSearch.search(DFSearch.java:79)
        at gov.nasa.jpf.JPF.run(JPF.java:613)
        at gov.nasa.jpf.JPF.start(JPF.java:189)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at gov.nasa.jpf.tool.Run.call(Run.java:80)
        at gov.nasa.jpf.tool.RunJPF.main(RunJPF.java:116)
Caused by: java.lang.UnsatisfiedLinkError: sun.management.OperatingSystemImpl.initialize()V
        at sun.management.OperatingSystemImpl.initialize(Native Method)
        at sun.management.OperatingSystemImpl.<clinit>(OperatingSystemImpl.java:54)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at OTF_JPF_sun_management_OperatingSystemImpl.initialize____V(OTF_JPF_sun_management_OperatingSystemImpl.class)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at gov.nasa.jpf.vm.NativeMethodInfo.executeNative(NativeMethodInfo.java:125)
        ... 15 more

The funny thing is that I cannot use the GenPeer tool either:

[jdanek@nixos:~/Work/repos/activemq-artemis/tests/stress-tests/target]$ java -cp ~/workspace/jpf-core/build/main  gov.nasa.jpf.tool.GenPeer -s -ci -m sun.management.OperatingSystemImpl > ~/workspace/jpf-core/src/peers/gov/nasa/jpf/vm/JPF_sun_management_OperatingSystemImpl.java
java.lang.UnsatisfiedLinkError: sun.management.OperatingSystemImpl.initialize()V
        at sun.management.OperatingSystemImpl.initialize(Native Method)
        at sun.management.OperatingSystemImpl.<clinit>(OperatingSystemImpl.java:54)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at gov.nasa.jpf.tool.GenPeer.getClass(GenPeer.java:75)
        at gov.nasa.jpf.tool.GenPeer.main(GenPeer.java:64)


I'll try to deal with this new exception tomorrow and post a new thread if I do not succeed on my own.

Thanks!
Reply all
Reply to author
Forward
0 new messages