Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.1.2
    • Fix Version/s: None
    • Component/s: Java Integration
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Sometimes it would be nice to permit this:

      public interface MyInterface {
        public void getProperty(String key);
      }
      
      Unable to find source-code formatter for language: ruby. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      obj.getProperty(:some_key)
      

      Currently this gives me:
      <unknown>:1: #<NameError::Message:0x4f77a035> (NoMethodError)

      To some extent it would be nice if hashes with Symbol keys could also support get() by string from the Java side, but that's probably a different enhancement and somewhat easier to work around in the first place.

        Activity

        Hide
        Bill Dortch added a comment -

        I once liked the idea myself, but am concerned about blurring the lines too much; if conversion rules are too lax, it could end up masking programming errors. I've thought for a while that the array conversion rules (which I originally, intentionally, made as lax as possible) really need to be tightened up. For example, this will actually "work":

        byte_arr = ['1', :b, Time.new].to_java :byte
        byte_arr[1] = '_2_'

        In the case of RubySymbols as Java strings, what makes me most uneasy is that the conversion only works in one direction; a String returned to Ruby from Java will still become a RubyString, even if it is interned. So here is what will happen:

          map = java.util.HashMap.new
          map[0] = :sym
          map[0]
         => "sym"
        

        I think this will be unexpected and confusing.

        Show
        Bill Dortch added a comment - I once liked the idea myself, but am concerned about blurring the lines too much; if conversion rules are too lax, it could end up masking programming errors. I've thought for a while that the array conversion rules (which I originally, intentionally, made as lax as possible) really need to be tightened up. For example, this will actually "work": byte_arr = ['1', :b, Time.new] .to_java :byte byte_arr [1] = '_ 2 _' In the case of RubySymbols as Java strings, what makes me most uneasy is that the conversion only works in one direction; a String returned to Ruby from Java will still become a RubyString, even if it is interned. So here is what will happen: map = java.util.HashMap.new map[0] = :sym map[0] => "sym" I think this will be unexpected and confusing.
        Hide
        Charles Oliver Nutter added a comment -

        Doesn't the hash case you demonstrate just store the RubySymbol object directly? The signature only takes Object, so there's nothing to coerce to.

        Show
        Charles Oliver Nutter added a comment - Doesn't the hash case you demonstrate just store the RubySymbol object directly? The signature only takes Object, so there's nothing to coerce to.
        Hide
        Bill Dortch added a comment -

        In my example above, that assumes that we always convert Ruby Symbols to Java Strings. If we only did so for String parameters, that might be less bad. Still don't like it, though.

        Show
        Bill Dortch added a comment - In my example above, that assumes that we always convert Ruby Symbols to Java Strings. If we only did so for String parameters, that might be less bad. Still don't like it, though.
        Hide
        Benjamin Bock added a comment -

        This issue is fixed in JRuby 1.4 but it's still marked as open here. I bisected the version which changed that behaviour, it's commit d7e5666becc3d3008f9f388f1e661d160749e402.
        Author: Charles Oliver Nutter <headius@headius.com>
        Date: Fri Oct 30 15:38:16 2009 -0500
        Fix for JRUBY-4189: calling to_java(:string) on a ruby array with a symbol in it now causes java exception

        If the concensus is to convert Ruby Symbols into Java Strings, this issue can be closed. Otherwise we have a new bug which is the opposite of this one.

        Show
        Benjamin Bock added a comment - This issue is fixed in JRuby 1.4 but it's still marked as open here. I bisected the version which changed that behaviour, it's commit d7e5666becc3d3008f9f388f1e661d160749e402. Author: Charles Oliver Nutter <headius@headius.com> Date: Fri Oct 30 15:38:16 2009 -0500 Fix for JRUBY-4189 : calling to_java(:string) on a ruby array with a symbol in it now causes java exception If the concensus is to convert Ruby Symbols into Java Strings, this issue can be closed. Otherwise we have a new bug which is the opposite of this one.
        Hide
        Hiro Asari added a comment -

        Indeed, this appears to be fixed. Thanks, Ben, for pointing it out.

        Show
        Hiro Asari added a comment - Indeed, this appears to be fixed. Thanks, Ben, for pointing it out.

          People

          • Assignee:
            Unassigned
            Reporter:
            Trejkaz
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: