History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-705
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: David Koontz
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JRuby

Cannot access protected member variables in Java base class

Created: 18/Mar/07 03:05 AM   Updated: 06/May/07 09:49 PM
Component/s: Java Integration
Affects Version/s: JRuby 0.9.8
Fix Version/s: JRuby 1.0.0RC1

Time Tracking:
Not Specified

Environment: Java 1.5.0_07-87, OSX 10.4.8, Head JRuby


 Description  « Hide
After inheriting from a Java class none of the protected variables are mapped into the Proxy class.

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
David Koontz - 19/Mar/07 03:39 AM
Public member variables are also not being added to the proxy class.

Charles Oliver Nutter - 27/Mar/07 02:36 PM
Perhaps there's a larger question here...how best to expose them? foo.bar looks for a bar() method on the foo object's class. This means that field accesses would require bar() and bar=() to be defined, incurring a method hit for all sets. But we may be constrained by what's practically possible in Ruby.

Are there other options? We already expose public static variables as methods (e.g. System.out) and I don't know of a better way, so perhaps it's already a moot point.


David Koontz - 28/Mar/07 03:32 PM
I assume your comment about exposing the variables is with regard to the public variables? Since bar() and bar()= methods are how Ruby operates it would make sense to map public in that manner as well although I do see your point about the extra method calls. Right now you have to use reflection to get at them so I think any implementation is probably better than that, performance wise.

Bill Dortch - 15/Apr/07 12:16 PM
Public member variables should be there (see JavaProxy.setup_attributes in builtin/javasupport/proxy/base.rb). See, for example,. java.awt.GridBagConstraints. They might be getting clobbered, though, by (generated) shortcut method names – my fix for JRUBY-778/JRUBY-814 should solve that.

However, if a public field name is the same as a declared public method name, the method will win. We could consider a naming strategy to get around this; prepending an underscore to the field name, for example, or appending '_field'. Another possibility is using the [] / []= operators, since this won't collide with any Java names. For example:

an_object = AJavaClass.new
an_object[:a_field_name] = a_value

Thoughts?

-Bill


Charles Oliver Nutter - 05/May/07 06:05 PM
Bill, go ahead and file another issue for the collision if it's still outstanding. You're right about the original issue being fixed though, so I'm marking this resolved.

Charles Oliver Nutter - 06/May/07 09:49 PM
Closing for 1.0RC1