Skip to content

java_send will not invoke a method taking a CharSequence #2881

@cshupp1

Description

@cshupp1

Consider the following in irb:

a = java.lang.StringBuilder.new
a.java_send :append, [java.lang.String], "I am Here\n"
puts a

yields I am Here as expected.

a.java_send :append, [java.lang.CharSequence], "I am not here!\n"
a.java_send :append, [java.lang.CharSequence], "I am not here!\n".to_java

both yield

TypeError: cannot convert instance of class org.jruby.RubyModule to class java.lang.Class
        from org/jruby/java/proxies/JavaProxy.java:347:in `java_send'
        from (irb):76:in `evaluate'
        from org/jruby/RubyKernel.java:1107:in `eval'
        from org/jruby/RubyKernel.java:1507:in `loop'
        from org/jruby/RubyKernel.java:1270:in `catch'
        from org/jruby/RubyKernel.java:1270:in `catch'
        from C:/jruby-1.7.18/bin/jirb:13:in `(root)'

Lets get extreme and open Ruby's String as follows:

class String
  include java.lang.CharSequence

  def charAt(index)
    self.to_java.charAt(index)
  end

  def length
    self.to_java.length
  end

  def subSequence(start, endPoint)
    self.to_java.subSequence(start, endPoint)
  end

  def toString
    self.to_java.toString()
  end

end

The code "SomeString".toString behaves as expected now, but:

 a.java_send :append, [java.lang.CharSequence], "Some String"
TypeError: cannot convert instance of class org.jruby.RubyModule to class java.lang.Class
        from org/jruby/java/proxies/JavaProxy.java:347:in `java_send'
        from (irb):81:in `evaluate'
        from org/jruby/RubyKernel.java:1107:in `eval'
        from org/jruby/RubyKernel.java:1507:in `loop'
        from org/jruby/RubyKernel.java:1270:in `catch'
        from org/jruby/RubyKernel.java:1270:in `catch'
        from C:/jruby-1.7.18/bin/jirb:13:in `(root)'

Still fails :-(

BTW:

irb(main):083:0> RUBY_VERSION
=> "1.9.3"
irb(main):084:0> JRUBY_VERSION
=> "1.7.18"
irb(main):085:0>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions