jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-574

kind_of? and < do not work properly for Java classes

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 0.9.2
  • Fix Version/s: JRuby 0.9.9
  • Component/s: Java Integration
  • Labels:
    None
  • Environment:
    Gentoo Linux/Java 5

Description

Expected behavior (using Ruby classes/modules):
>> Array < Enumerable
=> true
>> Array < Object
=> true
>> Array.new.kind_of? Enumerable
=> true
>> Array.new.kind_of? Object
=> true

Actual behavior when using Java classes/interfaces:
>> include_class('java.lang.Object') { |package, name| "J#{name}" }
>> include_class %w{ArrayList List}.map { |e| "java.util.#{e}" }
>> ArrayList < List
=> nil
>> ArrayList < JObject
=> nil
>> ArrayList.new.kind_of? List
=> false
>> ArrayList.new.kind_of? JObject
=> false

As near as I can tell, there is no workaround to this – it's not possible to do the equivalent of an "instance of" check against Java classes/objects in JRuby...

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. File
    jruby_kind_of.diff
    17/Apr/07 7:27 PM
    1 kB
    Martin Grund
  2. File
    ruby_module.diff
    19/Apr/07 5:50 PM
    1 kB
    Martin Grund
  3. File
    test_kind_of_with_java.rb
    19/Apr/07 5:50 PM
    1 kB
    Martin Grund
  4. File
    test_kind_of_with_java.rb
    17/Apr/07 7:28 PM
    1 kB
    Martin Grund

Issue Links

is duplicated by

Bug - A problem which impairs or prevents the functions of the product. JRUBY-236 kind_of doesn´t work with an java interface who extends another java interface

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
is superceded by

Bug - A problem which impairs or prevents the functions of the product. JRUBY-814 Multiple improvements to Java integration (was: Java method get lost.)

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Charles Oliver Nutter added a comment - 17/Apr/07 11:51 AM

See also the description for JRUBY-236.

Show
Charles Oliver Nutter added a comment - 17/Apr/07 11:51 AM See also the description for JRUBY-236.
Hide
Permalink
Martin Grund added a comment - 17/Apr/07 7:27 PM

Basically there is a pretty easy workaround for this bug, that makes at least Java type checking possible. I added an alias for the Ruby kind_of? method to allow the same check as already written in the java_kind_of? method, so that it looks like the following:

class Object

  alias :basic_kind_of? :kind_of?
  def kind_of?(other)
    return true if self.basic_kind_of?(other)
    return false unless self.respond_to?(:java_class) && other.respond_to?(:java_class) &&
      other.basic_kind_of?(Module) && !self.basic_kind_of?(Module) 
    return other.java_class.assignable_from?(self.java_class)
  end

  ....
end

Since the Object class defintion is serilized into the AST, this should not result in big performance issues. At least I hope so. I'll add a patch from the current trunk and a test to make sure, that this really works.

Show
Martin Grund added a comment - 17/Apr/07 7:27 PM Basically there is a pretty easy workaround for this bug, that makes at least Java type checking possible. I added an alias for the Ruby kind_of? method to allow the same check as already written in the java_kind_of? method, so that it looks like the following:
class Object

  alias :basic_kind_of? :kind_of?
  def kind_of?(other)
    return true if self.basic_kind_of?(other)
    return false unless self.respond_to?(:java_class) && other.respond_to?(:java_class) &&
      other.basic_kind_of?(Module) && !self.basic_kind_of?(Module) 
    return other.java_class.assignable_from?(self.java_class)
  end

  ....
end
Since the Object class defintion is serilized into the AST, this should not result in big performance issues. At least I hope so. I'll add a patch from the current trunk and a test to make sure, that this really works.
Hide
Permalink
Martin Grund added a comment - 17/Apr/07 7:27 PM

Patch to make it work

Show
Martin Grund added a comment - 17/Apr/07 7:27 PM Patch to make it work
Hide
Permalink
Martin Grund added a comment - 17/Apr/07 7:28 PM

unit test for this bug

Show
Martin Grund added a comment - 17/Apr/07 7:28 PM unit test for this bug
Hide
Permalink
Charles Oliver Nutter added a comment - 18/Apr/07 4:55 AM

If the patch is clean, we could include it in 0.9.9...otherwise at least 1.0?

Show
Charles Oliver Nutter added a comment - 18/Apr/07 4:55 AM If the patch is clean, we could include it in 0.9.9...otherwise at least 1.0?
Hide
Permalink
Martin Grund added a comment - 19/Apr/07 5:48 PM

I think, I solved the other issue as well. I "translated" the Ruby code from object.rb for Java type check to the respective method in RubyModule. I'll add the diff and the updated test file to prove.

Show
Martin Grund added a comment - 19/Apr/07 5:48 PM I think, I solved the other issue as well. I "translated" the Ruby code from object.rb for Java type check to the respective method in RubyModule. I'll add the diff and the updated test file to prove.
Hide
Permalink
Charles Oliver Nutter added a comment - 20/Apr/07 12:07 AM

Bill's fix for JRUBY-814 will fix this bug.

Show
Charles Oliver Nutter added a comment - 20/Apr/07 12:07 AM Bill's fix for JRUBY-814 will fix this bug.
Hide
Permalink
Charles Oliver Nutter added a comment - 20/Apr/07 1:20 PM

This will be fixed when we commit the JRUBY-814 patch some time today. Watch that bug for updates.

Show
Charles Oliver Nutter added a comment - 20/Apr/07 1:20 PM This will be fixed when we commit the JRUBY-814 patch some time today. Watch that bug for updates.

People

  • Assignee:
    Charles Oliver Nutter
    Reporter:
    Brian Ericson
Vote (0)
Watch (1)

Dates

  • Created:
    09/Feb/07 4:48 PM
    Updated:
    30/Apr/07 3:11 AM
    Resolved:
    20/Apr/07 1:20 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.