Invoking non-static method throws NullPointerException #14

Closed
xukaifu opened this Issue Oct 26, 2012 · 1 comment

Comments

Projects
None yet
2 participants

xukaifu commented Oct 26, 2012

stackTrace

java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at kilim.Task.invoke(Task.java:278)
at kilim.examples.Reflect.execute(Reflect.java:16)
at kilim.Task._runExecute(Task.java:432)
at kilim.WorkerThread.run(WorkerThread.java:32)

package kilim.examples;

import java.lang.reflect.Method;

import kilim.Pausable;
import kilim.Task;

public class Reflect extends Task {
    @Override
    public void execute() throws Pausable, Exception {
        int n = test();
        System.out.println("test (normal): " + n);

        // Invoking test() via reflection
        Method mthd = Reflect.class.getDeclaredMethod("test", new Class[0]);
        Object ret = Task.invoke(mthd, this, /* no args */(Object[]) null);
        System.out.println("test (reflect): " + ret);
        System.exit(0);
    }

   // non-static method
    public int test() throws Pausable {
        int m = 10;
        for (int i = 0; i < 2; i++) { // Force multiple yields
            Task.sleep(100);
            m *= 2;
        }
        return m; // must return 40 if all goes well.
    }

    public static void main(String args[]) {
        Reflect ref = new Reflect();
        ref.start();
        ref.joinb();
    }
}

@kilim kilim pushed a commit that referenced this issue Oct 28, 2012

@sriram-srinivasan sriram-srinivasan Issue #14. Task.invoke now invokes static methods correctly via refle…
…ction.

	modified:   .classpath
	modified:   examples/kilim/examples/Reflect.java
	modified:   src/kilim/Task.java
	modified:   src/kilim/mirrors/CachedClassMirrors.java
42c65b3
Owner

kilim commented Oct 28, 2012

Fixed in commit 42c65b3

kilim closed this Oct 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment