Skip to content

Commit fd91098

Browse files
author
Mike Ragalie
committed
Handle OnSubscribeFuncs correctly in JRuby interop logic
OnSubscribeFunc#onSubscribe expects to return a Subscription. I am unable to successfully cast the return value of a RubyProc, even if that value _is_ an object that implements the Subscription interface, into a Subscription in Java-land (Java reports that ConcreteJavaProxy cannot be cast). Instead I allow JRuby to handle OnSubscribeFunc arguments through its default proxy logic, which works correctly.
1 parent 2f44a8d commit fd91098

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

language-adaptors/rxjava-jruby/src/main/resources/rx/lang/jruby/interop.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module Lang
33
module Jruby
44
class Interop
55
WRAPPERS = {
6-
Java::RxUtilFunctions::Action => Java::RxLangJruby::JRubyActionWrapper
6+
Java::RxUtilFunctions::Action => Java::RxLangJruby::JRubyActionWrapper,
7+
Java::Rx::Observable::OnSubscribeFunc => false
78
}
89

910
WRAPPERS.default = Java::RxLangJruby::JRubyFunctionWrapper
@@ -33,6 +34,9 @@ def initialize
3334
type.ruby_class.ancestors.include?(java_class)
3435
end
3536

37+
# Skip OnSubscribeFuncs
38+
next if constructor && constructor.last == false
39+
3640
constructor = (constructor && constructor.last) || WRAPPERS.default
3741

3842
parameter_types[[method.name, method.static?]][idx] ||= []
@@ -52,7 +56,7 @@ def initialize
5256

5357
klass_to_open = static ? klass.singleton_class : klass
5458

55-
[method_name, underscore(method_name)].each do |name|
59+
[method_name, underscore(method_name)].uniq.each do |name|
5660
klass_to_open.send(:alias_method, "#{name}_without_wrapping", name)
5761
klass_to_open.send(:define_method, name) do |*args, &block|
5862
context = RUNTIME.get_current_context

language-adaptors/rxjava-jruby/src/spec/ruby/rx/lang/jruby/interop_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@
2929
observable.subscribe(1)
3030
end
3131

32+
it "doesn't wrap OnSubscribeFunc arguments" do
33+
proc = lambda {|observer| observer.onNext("hi")}
34+
Java::Rx::Observable.should_not_receive(:create_without_wrapping)
35+
Java::Rx::Observable.create(proc).should be_a(Java::Rx::Observable)
36+
end
37+
3238
it "works with underscoreized method names" do
33-
observable.should_receive(:finally_do_without_wrapping).with(kind_of(Java::RxLangJruby::JRubyActionWrapper))
39+
observable.
40+
should_receive(:finally_do_without_wrapping).
41+
with(kind_of(Java::RxLangJruby::JRubyActionWrapper)).
42+
and_call_original
43+
3444
observable.finally_do(lambda {})
3545
end
3646

0 commit comments

Comments
 (0)