Forum: JRuby JRuby 1.1.4 to 1.1.6: invokeSuper throwing NPE

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jim M. (Guest)
on 2008-12-19 19:03
(Received via mailing list)
* 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., removed_email_address@domain.invalid, 
removed_email_address@domain.invalid
http://www.io.com/~jimm/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Marcin M. (Guest)
on 2008-12-19 19:44
(Received via mailing list)
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
Jim M. (Guest)
on 2008-12-19 20:44
(Received via mailing list)
On Fri, Dec 19, 2008 at 12:44 PM, Marcin Mielżyński 
<removed_email_address@domain.invalid>
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
Jim M. (Guest)
on 2008-12-19 20:55
(Received via mailing list)
On Fri, Dec 19, 2008 at 1:43 PM, Jim M. <removed_email_address@domain.invalid>
wrote:
> On Fri, Dec 19, 2008 at 12:44 PM, Marcin Mielżyński 
<removed_email_address@domain.invalid> 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
This topic is locked and can not be replied to.