← 输入框|github.com|刷新
Skip to content

Undefined Method java_kind_of? in JRuby-9.3.0.0 #6862

Closed

Description

@ThomasKoppensteiner
(NoMethodError) undefined method `java_kind_of?' for #<Java::ComRabbitmqClientImpl::LongStringHelper::ByteArrayLongString:0xa79c8be> Did you mean? java_send

Environment Information
JRuby: jruby 9.3.0.0 (2.6.8) 2021-09-17 85c20e780f OpenJDK 64-Bit Server VM 11.0.12+0 on 11.0.12+0 [darwin-x86_64]
Dev OS: Darwin ofc-03052-m 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64

java_kind_of? is called here by the march_hare gem (version 4.3.0-java) (ruby-amqp/march_hare#155).

Expected Behavior

  • The java_kind_of? method is supported by JRuby-9.3.0.0

Actual Behavior

  • The java_kind_of? method is not supported by JRuby-9.3.0.0
  • The java_kind_of? method is supported by JRuby-9.2.19.0

Is java_kind_of? deprecated? Is there a replacement in JRuby-9.3.0.0?

Activity

  1. ThomasKoppensteiner commented on Sep 28, 2021

    @ThomasKoppensteiner
    Author

    Is java_kind_of? deprecated?

    Yes, it was deprecated in JRuby-9.2.19.0.

    See: https://github.com/jruby/jruby/blob/9.2.19.0/core/src/main/ruby/jruby/java/core_ext/object.rb#L13-L19

    # @deprecated
    def java_kind_of?(other) # TODO: this can go away now, but people may be using it
      return true if self.kind_of?(other)
      return false unless self.respond_to?(:java_class) && other.respond_to?(:java_class) &&
        other.kind_of?(Module) && !self.kind_of?(Module) 
      return other.java_class.assignable_from?(self.java_class)
    end
  2. michaelklishin commented on Sep 29, 2021

    @michaelklishin
    Contributor

    So what are our options then? Use #assignable_from? instead?

  3. enebo commented on Sep 29, 2021

    @enebo
    Member

    @ThomasKoppensteiner @michaelklishin Is kind_of? working for your needs here:

    a = java.util.ArrayList.new; p a.kind_of?(java.util.ArrayList) #=> true
    a = java.util.ArrayList.new; p a.kind_of?(java.util.List) #=> true
  4. ThomasKoppensteiner commented on Sep 30, 2021

    @ThomasKoppensteiner
    Author

    @enebo thank you for your suggestion. I used it in this PR for march_hare ruby-amqp/march_hare#156.

  5. enebo commented on Sep 30, 2021

    @enebo
    Member

    @ThomasKoppensteiner we talked about this on chat and realized for instance of sorts of checks kind_of? works but if you ask on Java type itself (e.g. java.util.ArrayList.kind_of?(java.lang.Class)) it does not. I think this is probably very uncommon but if you happen to ever notice this case we probably need to augment kind_of?.

  6. olleolleolle commented on Oct 5, 2021

    @olleolleolle
    Member

    The use-case in the ticket is the following:

    value.kind_of(com.rabbitmq.client.LongString) where value seems to be a Java value (we can see checks in there going value.is_a?(java.util.Map)).

    @enebo Would this be a valid?

    I searched for LONG_STRING_TYPE and found that value. https://github.com/ruby-amqp/march_hare/search?q=LONG_STRING_TYPE

  7. headius commented on Oct 5, 2021

    @headius
    Member

    Would this be a valid?

    I believe these should work with kind_of? or is_a as appropriate. The Ruby view of the Java object uses the same class hierarchy as e.g. com.rabbitmw.client.LongString and it should be seen as a supertype of the object's class.

  8. added this to the Won't Fix milestone on Oct 5, 2021
  9. headius commented on Oct 5, 2021

    @headius
    Member

    Closing as won't fix since kind_of? should work for all interesting use cases.

  10. added a commit that references this issue on Mar 29, 2022
  11. AxelPatron commented on May 16, 2023

    @AxelPatron

    Hello, I am using Logstash to process python script in my pipeline between SQL and ElasticSearch but if I use this filter in my logstash-sample.conf file
    filter { python { code => ' print("python works") ' } }
    I receive these logs :

    [2023-05-16T09:26:01,898][ERROR][logstash.filters.python ][main][9159e3828cc8f1ed140577832a7ee56f40772013e30def286e744cbc9c8f7eb1] Python exception occurred: undefined method java_kind_of?' for #Java::OrgPythonCore::PyObjectDerived:0x59f863d5
    Did you mean? java_send
    python works
    python works
    [2023-05-16T09:26:01,926][ERROR][logstash.filters.python ][main][9159e3828cc8f1ed140577832a7ee56f40772013e30def286e744cbc9c8f7eb1] Python exception occurred: undefined method java_kind_of?' for #<Java::OrgPythonCore::PyObjectDerived:0x1e55fe7e> Did you mean? java_send python works [2023-05-16T09:26:01,933][ERROR][logstash.filters.python ][main][9159e3828cc8f1ed140577832a7ee56f40772013e30def286e744cbc9c8f7eb1] Python exception occurred: undefined method java_kind_of?' for #Java::OrgPythonCore::PyObjectDerived:0x1e55fe7e`

    I am not sure it causes problems but what could I do to prevent that?
    I am using Logstash 8.6.2 wich uses JRuby to 9.3.10.0

  12. enebo commented on May 16, 2023

    @enebo
    Member

    @AxelPatron I don't know how you insert Ruby into conf (or some other file which happens to be Ruby syntax) but if you figure out such a place you can:

    class Object; alias java_kind_of? kind_of?; end

    I am guessing java_kind_of? is still being used by whatever provides python support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions