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

Invoking non-static method throws NullPointerException #14

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

Invoking non-static method throws NullPointerException #14

xukaifu opened this issue Oct 26, 2012 · 1 comment

Comments

@xukaifu
Copy link

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 pushed a commit that referenced this issue Oct 28, 2012
…ction.

	modified:   .classpath
	modified:   examples/kilim/examples/Reflect.java
	modified:   src/kilim/Task.java
	modified:   src/kilim/mirrors/CachedClassMirrors.java
@kilim
Copy link
Owner

kilim commented Oct 28, 2012

Fixed in commit 42c65b3

@kilim kilim closed this as completed Oct 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants