JRuby 1.1.4 to 1.1.6: invokeSuper throwing NPE

  • The short version:

I’m calling RuntimeHelpers.invokeSuper and see an NPE. This is because
the call to context.getFrameKlazz() is returning null. Why???

  • The long version:

I’m trying to upgrade from JRuby 1.1.4 to JRuby 1.1.6. I have classes
that subclass RubyArray and RubyHash. In those, I implement
method_missing in Java. If I don’t want to handle the missing method,
I call the super version.

In JRuby 1.1.4, I did this:

RuntimeHelpers.invokeAs(context, klazz.getSuperClass(), self,
“method_missing”, args, CallType.SUPER, block);

in JRuby 1.1.6, I am trying this:

RuntimeHelpers.invokeSuper(context, self, args, block);

but I’m seeing a NullPointerException. It looks like in 1.1.6 the
method RuntimeHelper.findImplementerIfNecessary is returning null. The
line that calls it assumes the return value is not null, thus the NPE:

RubyClass superClass =
findImplementerIfNecessary(self.getMetaClass(),
klazz).getSuperClass();

The second arg klazz is null, because the line before that

      RubyModule klazz = context.getFrameKlazz();

returns null. In other words, context.getFrameKlazz() is null, which
means findImplementerIfNecessary returns null, which causes the NPE.

What am I doing wrong?

Jim

Jim M., [email protected], [email protected]
http://www.io.com/~jimm/


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Does annotating the method via frame = true help ?

Marcin.

Jim M. pisze:

I call the super version.
but I’m seeing a NullPointerException. It looks like in 1.1.6 the

returns null. In other words, context.getFrameKlazz() is null, which
means findImplementerIfNecessary returns null, which causes the NPE.

What am I doing wrong?

Jim


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, Dec 19, 2008 at 12:44 PM, Marcin MielżyÅ„ski [email protected]
wrote:

Does annotating the method via frame = true help ?

I’m not sure how to do that because I’m not overriding the Java method
RubyKernal#method_missing directly, so I don’t know where to put the
annotation. Instead, I’m adding the method to my class via

klazz.addMethod(“method_missing”, new JavaMethod(klazz, PUBLIC) {
// …
});

Jim

On Fri, Dec 19, 2008 at 1:43 PM, Jim M. [email protected]
wrote:

On Fri, Dec 19, 2008 at 12:44 PM, Marcin MielżyÅ„ski [email protected] wrote:

Does annotating the method via frame = true help ?

Yes, it did. Thank you very much.

I’m not sure how to do that because I’m not overriding the Java method
RubyKernal#method_missing directly, so I don’t know where to put the
annotation. Instead, I’m adding the method to my class via

klazz.addMethod(“method_missing”, new JavaMethod(klazz, PUBLIC) {
// …
});

I changed this to
@JRubyMethod(name = “method_missing”, rest = true, frame = true,
module = true, visibility = PUBLIC)
public static IRubyObject method_missing(ThreadContext context,
IRubyObject self, IRubyObject[] args, Block block) {

just like in RubyKernel, and added the line
klazz.defineAnnotatedMethods(MyJavaClass.class);
to my class initializer code.

Thanks again for your help.

Jim