JRuby

java.lang.Class representation of Ruby class not retrievable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 0.9.2, JRuby 0.9.8, JRuby 0.9.9, JRuby 1.0.0RC1, JRuby 1.0.0RC2
  • Fix Version/s: JRuby 1.1.3
  • Component/s: None
  • Labels:
    None
  • Environment:
    Mac, Linux, Windows (XP and Vista)
  • Number of attachments :
    1

Description

Running the following code prints "java.lang.Object":

require 'java'

class Test < java.lang.Object; end

puts Test.java_class.name

#alternatively...
puts Test.new.getClass.name

Activity

Hide
Charles Oliver Nutter added a comment -

Here's a possible fix for this. It at least lets you get at the generated class with MyClass.java_class, as follows:

require 'java'
class Foo < java.lang.Object; end
Foo.java_class => org.jruby.javasupport.proxy.gen.Object$Proxy0

There's more work to do here in general, since we're creating a new class of objects that represent Java classes...I think we can reconcile the two worlds, but the code we have now needs a vast simplification...

Show
Charles Oliver Nutter added a comment - Here's a possible fix for this. It at least lets you get at the generated class with MyClass.java_class, as follows:
require 'java'
class Foo < java.lang.Object; end
Foo.java_class => org.jruby.javasupport.proxy.gen.Object$Proxy0
There's more work to do here in general, since we're creating a new class of objects that represent Java classes...I think we can reconcile the two worlds, but the code we have now needs a vast simplification...
Hide
Charles Oliver Nutter added a comment -

This won't be in RC2, but I'll leave it in hopes we can do it. Many people have asked for a way to get at the generated proxy class.

Show
Charles Oliver Nutter added a comment - This won't be in RC2, but I'll leave it in hopes we can do it. Many people have asked for a way to get at the generated proxy class.
Hide
Charles Oliver Nutter added a comment -

Post 1.0, since it's new Java integration functionality.

Show
Charles Oliver Nutter added a comment - Post 1.0, since it's new Java integration functionality.
Hide
Daniel Spiewak added a comment -

I've noticed the fix version on this keeps getting pushed back.

Just in case it wasn't known before, this is a bit of a blocker issue for me on some things. I know you guys have a lot of stuff to get done (esp for the 1.0 release train), but I would really like to see this sometime reasonably soon (post 1.0 is fine, but getting it pushed back years would probably be annoying).

Show
Daniel Spiewak added a comment - I've noticed the fix version on this keeps getting pushed back. Just in case it wasn't known before, this is a bit of a blocker issue for me on some things. I know you guys have a lot of stuff to get done (esp for the 1.0 release train), but I would really like to see this sometime reasonably soon (post 1.0 is fine, but getting it pushed back years would probably be annoying).
Hide
Charles Oliver Nutter added a comment -

I want it too...it's just that the 1.0 release has really been focused on getting Ruby working as well as possible, so some Java integration items have slipped to post 1.0. The next big thing we plan to hit after the 1.0 release is out is cleaning up and finishing off Java integration better than it is today.

Show
Charles Oliver Nutter added a comment - I want it too...it's just that the 1.0 release has really been focused on getting Ruby working as well as possible, so some Java integration items have slipped to post 1.0. The next big thing we plan to hit after the 1.0 release is out is cleaning up and finishing off Java integration better than it is today.
Hide
Daniel Spiewak added a comment -

No worries. Thanks for sticking it somewhere on the todo list.

Show
Daniel Spiewak added a comment - No worries. Thanks for sticking it somewhere on the todo list.
Hide
Charles Oliver Nutter added a comment -

Get this fixed for 1.1. It's not very big.

Show
Charles Oliver Nutter added a comment - Get this fixed for 1.1. It's not very big.
Hide
Charles Oliver Nutter added a comment -

Punting issues from 1.1 RC2 to 1.1 final.

Show
Charles Oliver Nutter added a comment - Punting issues from 1.1 RC2 to 1.1 final.
Hide
Charles Oliver Nutter added a comment -

I spent a good hour trying to figure out where to fix this today, and I have been defeated by Java integration. Punting to 1.2...we just need to rip and replace the JI stuff.

Daniel, the biggest thing that would help this move along would be starting to build up a suite of tests/specs for current Java integration capabilities and "wished for" features like this. That's what we want to be able to finally fix up java integration the right way.

Show
Charles Oliver Nutter added a comment - I spent a good hour trying to figure out where to fix this today, and I have been defeated by Java integration. Punting to 1.2...we just need to rip and replace the JI stuff. Daniel, the biggest thing that would help this move along would be starting to build up a suite of tests/specs for current Java integration capabilities and "wished for" features like this. That's what we want to be able to finally fix up java integration the right way.
Hide
Daniel Spiewak added a comment -

Well, point me in the right direction and I'll see what I can do to help out. I can't do too much due to spare-time constraints, but I'll do what I can. Once this is fixed, some very cool possibilities open up regarding JRuby use-cases.

Show
Daniel Spiewak added a comment - Well, point me in the right direction and I'll see what I can do to help out. I can't do too much due to spare-time constraints, but I'll do what I can. Once this is fixed, some very cool possibilities open up regarding JRuby use-cases.
Hide
Charles Oliver Nutter added a comment -

Really, it's just a matter of submitting test cases for basically any functionality you'd expect to have in Java integration, even down to simple method call logic on Java types. We have some of that in larger cases, but very little of it in explicit test cases. That's what we need...so some possible categories for tests:

  • Java classes entering the system and introspecting like they're Ruby classes
  • Java object instances entering the system and behaving like Ruby objects (normal Ruby operations working like to_s, type, etc)
  • Java object instances entering the system and exposing appropriate methods
  • Type coercion working as expected where you want it to, like numeric types coercing to Ruby numeric types in sane ways
  • Noncoercing methods getting decorated with behaviors you'd expect to see, like making Java Collection work as a Ruby Enumerable, and so on. This would probably also include cases for Java numeric types exposing appropriate coercion and operations as Ruby numeric types.
  • Method selection logic mapping to what you would expect given specific types. So if you call with a fixnum, would you expect it to try to call the narrowest method for the fixnum value, or a "long" version all the time?
  • Inherited methods working correctly
  • Reopening Java types and having access to actual class internals. This may or may not be possible, but it's something people expect to be possible.
  • Subclassing of Java types, making sure polymorphic dispatch works and making sure superclass protected members are available
  • Interface implementation, making sure dispatch for a wide range of interface method types work correctly

And there's much more, of course.

Show
Charles Oliver Nutter added a comment - Really, it's just a matter of submitting test cases for basically any functionality you'd expect to have in Java integration, even down to simple method call logic on Java types. We have some of that in larger cases, but very little of it in explicit test cases. That's what we need...so some possible categories for tests:
  • Java classes entering the system and introspecting like they're Ruby classes
  • Java object instances entering the system and behaving like Ruby objects (normal Ruby operations working like to_s, type, etc)
  • Java object instances entering the system and exposing appropriate methods
  • Type coercion working as expected where you want it to, like numeric types coercing to Ruby numeric types in sane ways
  • Noncoercing methods getting decorated with behaviors you'd expect to see, like making Java Collection work as a Ruby Enumerable, and so on. This would probably also include cases for Java numeric types exposing appropriate coercion and operations as Ruby numeric types.
  • Method selection logic mapping to what you would expect given specific types. So if you call with a fixnum, would you expect it to try to call the narrowest method for the fixnum value, or a "long" version all the time?
  • Inherited methods working correctly
  • Reopening Java types and having access to actual class internals. This may or may not be possible, but it's something people expect to be possible.
  • Subclassing of Java types, making sure polymorphic dispatch works and making sure superclass protected members are available
  • Interface implementation, making sure dispatch for a wide range of interface method types work correctly
And there's much more, of course.
Hide
Charles Oliver Nutter added a comment -

Damn the torpedoes, I'm going to resolve this in 1.1.2 if it kills me.

Show
Charles Oliver Nutter added a comment - Damn the torpedoes, I'm going to resolve this in 1.1.2 if it kills me.
Hide
Charles Oliver Nutter added a comment -

Ok, the syntax isn't great, but you can now access MySubclass.java_proxy_class.java_class to get the actual class associated. We'll come up with something better for the new Java support.

Show
Charles Oliver Nutter added a comment - Ok, the syntax isn't great, but you can now access MySubclass.java_proxy_class.java_class to get the actual class associated. We'll come up with something better for the new Java support.
Hide
Daniel Spiewak added a comment -

I tried this against trunk/ (updated today), didn't seem to work.

PS C:\Users\Daniel Spiewak\Applications\jruby\bin> .\jirb
irb(main):001:0> class MySubclass < java.lang.Object; end
=> nil
irb(main):002:0> MySubclass.java_proxy_class.java_class
NoMethodError: undefined method `java_class' for nil:NilClass
from (irb):3:in `binding'
irb(main):003:0> MySubclass.java_proxy_class
=> nil
irb(main):004:0> MySubclass.java_class
=> java.lang.Object
irb(main):005:0>

Show
Daniel Spiewak added a comment - I tried this against trunk/ (updated today), didn't seem to work. PS C:\Users\Daniel Spiewak\Applications\jruby\bin> .\jirb irb(main):001:0> class MySubclass < java.lang.Object; end => nil irb(main):002:0> MySubclass.java_proxy_class.java_class NoMethodError: undefined method `java_class' for nil:NilClass from (irb):3:in `binding' irb(main):003:0> MySubclass.java_proxy_class => nil irb(main):004:0> MySubclass.java_class => java.lang.Object irb(main):005:0>
Hide
Daniel Spiewak added a comment -

False alarm:

irb(main):012:0> MyFrame.java_proxy_class.java_class
=> org.jruby.javasupport.proxy.gen.JFrame$Proxy0

Seems you have to a) derive from something other than Object, and b) do something with the class to force the JIT to kick in. It would be nice if invoking java_proxy_class would trigger the JIT in any case, but this isn't too bad. Thanks for the fix!

Show
Daniel Spiewak added a comment - False alarm: irb(main):012:0> MyFrame.java_proxy_class.java_class => org.jruby.javasupport.proxy.gen.JFrame$Proxy0 Seems you have to a) derive from something other than Object, and b) do something with the class to force the JIT to kick in. It would be nice if invoking java_proxy_class would trigger the JIT in any case, but this isn't too bad. Thanks for the fix!
Hide
Charles Oliver Nutter added a comment -

Should be able to get this into 1.1.3.

Show
Charles Oliver Nutter added a comment - Should be able to get this into 1.1.3.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: