Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined Method java_kind_of? in JRuby-9.3.0.0 #6862

Closed
ThomasKoppensteiner opened this issue Sep 28, 2021 · 10 comments
Closed

Undefined Method java_kind_of? in JRuby-9.3.0.0 #6862

ThomasKoppensteiner opened this issue Sep 28, 2021 · 10 comments
Milestone

Comments

@ThomasKoppensteiner
Copy link

ThomasKoppensteiner commented Sep 28, 2021

(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?

@ThomasKoppensteiner
Copy link
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

@michaelklishin
Copy link
Contributor

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

@enebo
Copy link
Member

enebo commented Sep 29, 2021

@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

@ThomasKoppensteiner
Copy link
Author

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

@enebo
Copy link
Member

enebo commented Sep 30, 2021

@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?.

@olleolleolle
Copy link
Member

olleolleolle commented Oct 5, 2021

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

@headius
Copy link
Member

headius commented Oct 5, 2021

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.

@headius headius added this to the Won't Fix milestone Oct 5, 2021
@headius
Copy link
Member

headius commented Oct 5, 2021

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

@AxelPatron
Copy link

AxelPatron commented May 16, 2023

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

@enebo
Copy link
Member

enebo commented May 16, 2023

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants