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-29

Included Java classes will overwrite Ruby proxy methods or existing Ruby methods

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 0.9.0
  • Fix Version/s: JRuby 0.9.9
  • Component/s: Java Integration
  • Labels:
    None

Description

Lets say you have a java class like:

class Foo {
public int id() {...}
}

If you include_class 'Foo' then the Java impl of id will replace the Ruby impl. It is even worse in the case of convenience aliases:

class Foo {
public int getId() {...}
}

This will overwrite id as well. We regressed on this behavior during 0.9.0 development.
The fix is fairly straight-forward we check all methods and aliases against proxy to see if a method already exists and if so then we don't create it.

Issue Links

is related to

Bug - A problem which impairs or prevents the functions of the product. JRUBY-778 basic Swing usage causes SystemStackError

  • Blocker - Blocks development and/or testing work, production could not run
  • 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 - 10/Aug/06 4:24 PM

Should fix in 091, it's burned a few people.

Show
Charles Oliver Nutter added a comment - 10/Aug/06 4:24 PM Should fix in 091, it's burned a few people.
Hide
Permalink
Charles Oliver Nutter added a comment - 17/Apr/07 1:05 PM

It's likely that BIll's fixes for JRUBY-778 will result in a fix for this bug.

Show
Charles Oliver Nutter added a comment - 17/Apr/07 1:05 PM It's likely that BIll's fixes for JRUBY-778 will result in a fix for this bug.
Hide
Permalink
Charles Oliver Nutter added a comment - 20/Apr/07 12:05 AM

Bill's patch for 814 will fix this bug.

Show
Charles Oliver Nutter added a comment - 20/Apr/07 12:05 AM Bill's patch for 814 will fix this bug.
Hide
Permalink
Bill Dortch added a comment - 20/Apr/07 8:16 AM

Actually, the JRUBY-814 patch doesn't exactly fix this. It doesn't check for methods defined in any pure Ruby classes/modules defined above the top of the Java hierarchy: ConcreteJavaProxy, JavaProxy, Object, Kernel and Java. And I would propose that it's fine (and necessary) for Java methods to be able to override methods defined in those classes.

What the 814 patch does provide is a standard place to define Ruby methods that should never be overridden, the RESERVED_NAMES HashMap in org.jruby.javasupport.JavaClass. Right now, that list includes only one name: class. I've just added _id_ and object_id as well, so that makes three.

So, we should think about which names must be absolutely excluded. But here lies a problem, and the example in this issue goes right to it. What about a name like 'id' ? Aside from the fact that it's now deprecated in Ruby (with good reason), it's a common identifier used in many Java applications. There are many other Ruby methods that collide with common names, as a quick look at the RDoc for Object and Kernel will confirm.

As I write this, I've just added a new category to JavaClass$AssignedName: WEAKLY_RESERVED (motto "we'll be peeved, but not devastated, if you override") , and added 'id' to it. Java method and field names can override it, but aliases wont. I've also decided to break RESERVED_NAMES into separate static and instance lists, since a name like 'new' shouldn't be excluded as an instance method (but really must be as a class method).

But in the end, I think the user needs to be able to specify which Ruby names are off-limits. This functionality will be easy to implement, and there are a couple of ways it can be exposed:

1. A method on the Java module, e.g., Java.dont_even_think_about_overriding "my_word"
2. An ENV variable, e.g. ENV['JAVA_EXCLUDE'] << ';my_word'
3. ???

Thoughts?

-Bill

Show
Bill Dortch added a comment - 20/Apr/07 8:16 AM Actually, the JRUBY-814 patch doesn't exactly fix this. It doesn't check for methods defined in any pure Ruby classes/modules defined above the top of the Java hierarchy: ConcreteJavaProxy, JavaProxy, Object, Kernel and Java. And I would propose that it's fine (and necessary) for Java methods to be able to override methods defined in those classes. What the 814 patch does provide is a standard place to define Ruby methods that should never be overridden, the RESERVED_NAMES HashMap in org.jruby.javasupport.JavaClass. Right now, that list includes only one name: class. I've just added _id_ and object_id as well, so that makes three. So, we should think about which names must be absolutely excluded. But here lies a problem, and the example in this issue goes right to it. What about a name like 'id' ? Aside from the fact that it's now deprecated in Ruby (with good reason), it's a common identifier used in many Java applications. There are many other Ruby methods that collide with common names, as a quick look at the RDoc for Object and Kernel will confirm. As I write this, I've just added a new category to JavaClass$AssignedName: WEAKLY_RESERVED (motto "we'll be peeved, but not devastated, if you override") , and added 'id' to it. Java method and field names can override it, but aliases wont. I've also decided to break RESERVED_NAMES into separate static and instance lists, since a name like 'new' shouldn't be excluded as an instance method (but really must be as a class method). But in the end, I think the user needs to be able to specify which Ruby names are off-limits. This functionality will be easy to implement, and there are a couple of ways it can be exposed: 1. A method on the Java module, e.g., Java.dont_even_think_about_overriding "my_word" 2. An ENV variable, e.g. ENV['JAVA_EXCLUDE'] << ';my_word' 3. ??? Thoughts? -Bill
Hide
Permalink
Thomas E Enebo added a comment - 20/Apr/07 9:52 AM

WEAKLY_RESERVED is needed, seems like a great solution and ultimately most developers should be reasonably satisfied with our defaults. Having the ability to tailor this will also satisfy those who need something more. I am not sure if this should be super global (env will affect all runtimes in a VM), global (one VM), a profile which can be applied so only some included classes? I am not a huge fan of an ENV.

Show
Thomas E Enebo added a comment - 20/Apr/07 9:52 AM WEAKLY_RESERVED is needed, seems like a great solution and ultimately most developers should be reasonably satisfied with our defaults. Having the ability to tailor this will also satisfy those who need something more. I am not sure if this should be super global (env will affect all runtimes in a VM), global (one VM), a profile which can be applied so only some included classes? I am not a huge fan of an ENV.
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:
    Thomas E Enebo
Vote (0)
Watch (1)

Dates

  • Created:
    17/Jul/06 8:18 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.