Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 07be559

Browse files
committed
Adapt JRuby arity workaround to BlockSignature
The workaround looking up the corresponding Java class and looking at its methods only works for methods, and doesn't work for Proc, where there isn't a direct API to access the proxied Java class. While the same problem exists for Proc's, until jruby/jruby#2817 has been resolved, there isn't much that can be done for that case. However, the current code fails to run for all blocks with arity -1, so this tweak is necessary to ensure normal blocks work again. I couldn't find any specs for BlockSignature, so wasn't sure where it would be appropriate to add a test for this.
1 parent 383b4f9 commit 07be559

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/rspec/support/method_signature_verifier.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,19 @@ def classify_parameters
180180
# aliases to make method names look more Rubyesque). If there is only a
181181
# single match, we can use that methods arity directly instead of the
182182
# default -1 arity.
183+
#
184+
# This workaround only works for Java proxy methods, and in order to
185+
# support regular methods and blocks, we need to be careful about calling
186+
# owner and java_class as they might not be available
183187
if Java::JavaLang::String.instance_method(:char_at).arity == -1
184188
class MethodSignature < remove_const(:MethodSignature)
185189
private
186190

187191
def classify_parameters
188192
super
189-
return unless @method.arity == -1 && @method.owner.respond_to?(:java_class)
193+
return unless @method.arity == -1
194+
return unless @method.respond_to?(:owner)
195+
return unless @method.owner.respond_to?(:java_class)
190196
java_instance_methods = @method.owner.java_class.java_instance_methods
191197
compatible_overloads = java_instance_methods.select do |java_method|
192198
@method == @method.owner.instance_method(java_method.name)

0 commit comments

Comments
 (0)