Skip to content

[Probably a question, but perhaps also a possibility for improvement] Getting method(:foobar).source_location to work? #8427

@rubyFeedback

Description

@rubyFeedback

So I am still extending my java-swing and jruby foobar.

In ruby I am quite used to this:

puts method(:name_of_the_method).source_location

To my (slight) surprise this does not seem to work in jruby-swing:

puts method(:mouseEnter).source_location

I was trying to find out what parameters mouseEnter would need, and
I did not know where it was defined.

To my surprise, jruby did not show where the source location is defined.
But, even stranger ... jruby seems to completely be silent about it. Actually
it will just return nil.

Now ... I assume that it may not be trivial to get the information where the
source is, as it is java, and perhaps there is a lack of cross-information between
java code and ruby code. But I believe that returning nil here is still wrong.
I can kind of understand the rationale, and if that method can not be made
better, then I guess nil is the most sensible default return value - but when I
used it, I was surprised that nothing seemed to happen at all. This is very
different to default MRI behaviour, in my opinion. Granted, now that I know
about this it is not so bad, but initially I thought I had a bug in my code.

Of course the best solution would be to show the java-source code or path,
though perhaps that can not be made available.

The method exists, and I can verify this when I pass a wrong number of arguments to it:

mouseEnter(nil, nil)

Caused by: org.jruby.exceptions.ArgumentError: (ArgumentError) wrong number of arguments (given 2, expected 3)
    ... 1 more

^^^^

(I am actually trying to find documentation for the API there, for jruby.)

Anyway - I'll close this to keep the bug tracker clean and there is probably not a simple solution. It is just surprising that the source location was not returned, but the method still may exist and also cause exceptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions