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

[1.6.7-HEAD] RubyArray/RubyHash/etc cannot be passed into Java code as themselves #166

Closed
arturaz opened this issue May 9, 2012 · 13 comments

Comments

@arturaz
Copy link

arturaz commented May 9, 2012

@headius

jruby 1.6.8.dev (ruby-1.9.2-p312) (2012-04-22 985cae8) (Java HotSpot(TM) Client VM 1.7.0) [linux-i386-java]

If I have following method signature in Scala:

def calc(formula: String, vars: RubyHash)

I cannot call this:

java_obj.call("foo", {3 => 4})

For example"

>> Java::SpacemuleModulesConfigObjects::FormulaCalc.rubyCalc(3)
NameError: no method 'rubyCalc' for arguments (org.jruby.RubyFixnum) on Java::SpacemuleModulesConfigObjects::FormulaCalc
   available overloads:
     (org.jruby.RubyFixnum)

 NameError: no method 'calc' for arguments (org.jruby.RubyString,org.jruby.RubyHash) on Java::SpacemuleModulesConfigObjects::FormulaCalc
   available overloads: (org.jruby.RubyString,org.jruby.RubyHash)
 WAT?

It seems this happens if even one of the args is tried to pass as their native representation.

@headius
Copy link
Member

headius commented May 9, 2012

Ok, I am able to reproduce this; it only appears to affect the case of overloading. Overload logic is a bit stricter about types because it has to pick the best match, but in this case it seems to be too strict and not allowing Ruby types to go through as-is.

Blah.java:


public class Blah {
  public static void foo(Object... objs) {
  }

  public static void bar(int a) {
  }

  public static void baz(int i, org.jruby.RubyHash hash) {
  }
  public static void baz(String s, org.jruby.RubyHash hash) {
  }
}

And failure:

system ~/projects/jruby $ jruby -rjava -e "Java::Blah.baz('foo', 1 => 2)"
NameError: no method 'baz' for arguments (org.jruby.RubyString,org.jruby.RubyHash) on Java::Default::Blah
  available overloads:
    (java.lang.String,org.jruby.RubyHash)
    (int,org.jruby.RubyHash)
  (root) at -e:1

Investigating.

@arturaz
Copy link
Author

arturaz commented May 14, 2012

This probably belongs here...

NameError: no method 'run' for arguments (spacemule.modules.combat.objects.Location,org.jruby.RubyBoolean,scala.None$,org.jruby.RubyObject,org.jruby.RubyHash,org.jruby.RubyHash,org.jruby.RubyObject,org.jruby.RubyHash,org.jruby.RubyObject,org.jruby.RubyObject) on Java::SpacemuleModulesCombat::Runner
  available overloads:
    (spacemule.modules.combat.objects.Location,boolean,scala.Option,org.jruby.runtime.builtin.IRubyObject,org.jruby.RubyHash,org.jruby.RubyHash,org.jruby.runtime.builtin.IRubyObject,org.jruby.RubyHash,org.jruby.runtime.builtin.IRubyObject,org.jruby.runtime.builtin.IRubyObject)

@arturaz
Copy link
Author

arturaz commented May 14, 2012

Could you please please please fix this? :) I've hit a roadblock and cannot do any work because of this :(

@arturaz
Copy link
Author

arturaz commented May 14, 2012

Method signature.

  def run(
    location: Location,
    isBattleground: Boolean,
    planetOwner: Option[Player],
    rbPlayers: IRubyObject, // Set[Option[Player]],
    rbAllianceNames: RubyHash, // Combat.AllianceNames
    rbNapRules: RubyHash, // Combat.NapRules,
    rbTroops: IRubyObject, // Set[Troop],
    rbLoadedTroops: RubyHash, // Map[Long, Set[Troop]],
    rbUnloadedTroopIds: IRubyObject, // Set[Long],
    rbBuildings: IRubyObject // Set[Building]
  ): Option[Response] = { ... }

@arturaz
Copy link
Author

arturaz commented May 15, 2012

:(

I can't even work around this...
Interesting thing is that jruby reports two identical overloads...

NameError: no method 'run' for arguments (spacemule.modules.combat.objects.Location,org.jruby.RubyBoolean,scala.None$,org.jruby.java.proxies.ArrayJavaProxy,org.jruby.RubyHash,org.jruby.RubyHash,org.jruby.java.proxies.ArrayJavaProxy,org.jruby.RubyHash,org.jruby.RubyObject,org.jruby.java.proxies.ArrayJavaProxy) on Java::SpacemuleModulesCombat::Runner
available overloads:
(spacemule.modules.combat.objects.Location,boolean,scala.Option,scala.Option[],java.util.Map,java.util.Map,spacemule.modules.combat.objects.Troop[],java.util.Map,long[],spacemule.modules.combat.objects.Building[])
(spacemule.modules.combat.objects.Location,boolean,scala.Option,scala.Option[],java.util.Map,java.util.Map,spacemule.modules.combat.objects.Troop[],java.util.Map,long[],spacemule.modules.combat.objects.Building[])

@headius
Copy link
Member

headius commented May 18, 2012

It probably reports two overloads because Scala also overloads methods on return type. That's a very difficult problem to solve, since we have no way to pick the overload you actually want or need...

@arturaz
Copy link
Author

arturaz commented May 18, 2012

But there is no overloads in scala code. And afaik scala does not have overloads on return type...

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Charles Oliver Nutter reply@reply.github.com wrote:

It probably reports two overloads because Scala also overloads methods on return type. That's a very difficult problem to solve, since we have no way to pick the overload you actually want or need...


Reply to this email directly or view it on GitHub:
#166 (comment)

@headius
Copy link
Member

headius commented May 18, 2012

Scala may not allow defining overloads on return type, but it definitely does generate overloads based on return type.

@arturaz
Copy link
Author

arturaz commented May 18, 2012

Java does not support this. Is this a low level jvm feature?

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Charles Oliver Nutter reply@reply.github.com wrote:

Scala may not allow defining overloads on return type, but it definitely does generate overloads based on return type.


Reply to this email directly or view it on GitHub:
#166 (comment)

@arturaz
Copy link
Author

arturaz commented May 18, 2012

Perhaps print the return type in overload list then as well?

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Charles Oliver Nutter reply@reply.github.com wrote:

Scala may not allow defining overloads on return type, but it definitely does generate overloads based on return type.


Reply to this email directly or view it on GitHub:
#166 (comment)

@rtyler
Copy link

rtyler commented Dec 3, 2014

@arturaz have you tried recent versions of JRuby 1.7 to see if this issue is still around? I'd love to close this sucker if it's no longer relevant :P

@arturaz
Copy link
Author

arturaz commented Dec 4, 2014

No, I don't use Ruby anymore, migrated to Scala :)

On Wed, Dec 3, 2014 at 8:12 PM, R. Tyler Croy notifications@github.com
wrote:

@arturaz https://github.com/arturaz have you tried recent versions of
JRuby 1.7 to see if this issue is still around? I'd love to close this
sucker if it's no longer relevant :P


Reply to this email directly or view it on GitHub
#166 (comment).

@rtyler
Copy link

rtyler commented Dec 4, 2014

Bummer dude, I'm going to go ahead and close this out then.

@rtyler rtyler closed this as completed Dec 4, 2014
@enebo enebo added this to the Invalid or Duplicate milestone Dec 8, 2014
headius added a commit that referenced this issue Jan 12, 2016
70b1140 Spec the default values of IO#sync for standard streams.
7753d2f Reorder Zlib deflate specs
76488f6 Fix warning in Zlib deflate spec
763d9ea Add specs for streaming in inflate processing
f484f34 Solaris 10 on x86 wrongly returns ai_pprotocol as 0
a5c0605 Remove bad spec
8b118fd Specify new behavior for Enumerable{chunk,slice_before}
5885e2b Initial spec for Queue#close and Queue#closed?
ba17b3d Spec for the new behavior of Kernel#loop
f59a862 No silent rescue in Comparable#<=> is now released behavior in 2.3
9a20b87 Treat paths with unicode characters as binary to avoid depending on the locale.
5ab735b Merge pull request #180 from ruby/string-split
0d2c110 Add more String#split examples
68159c3 Skip filesystem encoding dependent spec
fe83324 Remove old guarded spec, implementations should be allowed to do either.
0db9d4a  Fix IO#write_nonblock spec under 2.0
40957a3 Fix IO#read_nonblock spec under 2.0
fc0d729 Add a spec covering calling #instance_eval with a proc from a method
e32825a Added specs for RARRAY_AREF.
997fc93 Added spec for IO#write_nonblock raising
45dcbd1 Test IO#read_nonblock raising EAGAINWaitReadable
400a56f Fix a typo s/refering/referring/
c76d706 Fixed Dir.pwd spec with unicode characters.
0512054 Add spec about -> lambda scoping.
f0b6cf6 Accomodate for Thread#backtrace being nil when thread is not started yet.
7462ac9 BigDecimal.new raises ArgumentError when Float is used without precision
79f43c0 do not raise when precision is passed to BigDecimal#round
26ac864 Fix line in Exception#backtrace spec.
2269430 Move the fixture class to fixtures.
d799042 Merge pull request #178 from yuki24/add-spec-for-name-error-receiver
abee55f Merge pull request #177 from yuki24/add-specs-for-name-error-name
fc420f3 Add specs for NameError#name
c127124 Add more examples for NameError#receiver
b09e8fd Simplify a spec for NameError#receiver
674b32f Speficy that hidden metaclasses stay hidden.
7b99cfc Merge pull request #179 from yuki24/use-latest-rubies
0d96eb5 Use the latest rubies on Travis
2617339 Add spec for Symbol#to_proc plus Proc#parameters => [[:rest]]
bbcb689 Mask out specs+fixtures for keyreq added in 2.1.
df59b1f Add some simple specs for Method#parameters with keyword args.
bac69ca wait for the parent to read
4960e98 Revert "wait for the parent to read" because of stall on Solaris
822aac3 NetHTTPSpecs.start_server should not use hardcoded port number.
379401f Fix and complete Thread#name spec.
9912132 [ruby-2.3 core/thread] - Add specs for Thread#name and Thread#name=
ae8ef6a Explicitly state the relation between classes since this spec is meta-meta
1a31f57 Merge pull request #173 from nobu/bug/fd-passing-tests
652d332 wait for the parent to read
f60ee1e Merge pull request #172 from nobu/feature/dig_change
e34b1a4 separate TypeError cases on dig
7526c4e Merge pull request #171 from nobu/feature/dig_change
4d25005 dig method update
2f8577d Ruby 2.3 doesn't raise error
72b2688 Specify the behavior of Date#<< with respect to the version
f8358bd Merge pull request #170 from nobu/bug/Date-minus_month-exception
1fdd93d do not mind excepction class
53f535b Merge pull request #168 from cthulhua/chunk_while
f4ae8fc [ruby-2.3 core/enumerable] - Add specs for enumerable#chunk_while
1b726f7 Merge pull request #167 from nobu/bug/fix-infection-from-range
2a8f30a Fix version to ruby_bug
67fb1f7 Merge pull request #166 from nobu/bug/fix-infection-from-range
7198825 Fix infection from Range
e1b1ba6 Use the container infrastructure on Travis CI
5cec3a3 Fix UTF-8 Encoding constant name in StringIO specs
c330bfd Fix StringIO specs file structure
e148e90 Fix StringIO#isatty describe title
1f358a4 Fix location of ObjectSpace fixtures.

git-subtree-dir: spec/ruby
git-subtree-split: 70b11404aa1f44e18b560d3d0de78ef827c1434e
eregon added a commit that referenced this issue Feb 2, 2016
d9a07bf Module#define_method behaved differently with visibility in 2.0.0
38fdfa7 Module#prepend is private in 2.0.0
09374e5 New spec for visibility with Module#define_method and UnboundMethod
bc87a91 Fix UnboundMethod#owner specs to actually use UnboundMethod.
05f25e3 Fix spec description in Method#owner.
5a39e5a Add spec for prepend in the presence of define_method super.
42f6a39 Add example for SizedQueue#num_waiting
f27b277 Clearer name in class_variable_get spec
10a5eb4 Spec for U with malformed UTF-8 sequences.
ce8d46b Show the command when linking fails
25f9b87 Get rid of all "should_not raise_error" in language specs
6dba10a Better way to check the exact error class
a2e628f Fix bad expectation
fa031c0 Merge pull request #184 from phluid61/20160120-float-0x1p1
8bd00d6 add descriptive wrapper and tests for base case
cdd29a8 add tests for Float('0x1p1') and Float('0x1P1')
162df6a Add --disable-gems to support icc
a90ecb2 Fix Float::EPSILON spec
d8d81ef Cut to a decent amount of precision for Float::MIN and MAX
01278ce Float::MIN is 2.2250738585072e-308 in Ruby
253a399 Unify Bignum#size spec
774563a Fix typo
9011723 Use 1.9-style for Hash literals
102bf17 It seems #eval can be aliased on multiple implementations
a9a24cd Remove deviates_on behaving as the compliant specs
d0b5223 Replace hash_class by Hash
c7ca97d Use Hash literals instead of the new_hash helper
d4483ff Fix year in the history section
75ec48b Try to clarify what it is and what it is not
fec9f62 Fix wording in the history section
ad889cc Fix reference in C extension specs header
179f605 rb_str_len is not public API
6536b8b Remove old and unused version file
976c99a Fix a typo
dd6b920 Fix references in CONTRIBUTING
35f18ac Add a section about the history and RubySpec
09adfe9 Fix a few more names in the README
217fbbe Update README to reflect the new name
878ed3e Fix URLs to point the new repo name.
70b1140 Spec the default values of IO#sync for standard streams.
7753d2f Reorder Zlib deflate specs
76488f6 Fix warning in Zlib deflate spec
763d9ea Add specs for streaming in inflate processing
f484f34 Solaris 10 on x86 wrongly returns ai_pprotocol as 0
a5c0605 Remove bad spec
8b118fd Specify new behavior for Enumerable{chunk,slice_before}
5885e2b Initial spec for Queue#close and Queue#closed?
ba17b3d Spec for the new behavior of Kernel#loop
f59a862 No silent rescue in Comparable#<=> is now released behavior in 2.3
9a20b87 Treat paths with unicode characters as binary to avoid depending on the locale.
5ab735b Merge pull request #180 from ruby/string-split
0d2c110 Add more String#split examples
68159c3 Skip filesystem encoding dependent spec
fe83324 Remove old guarded spec, implementations should be allowed to do either.
0db9d4a  Fix IO#write_nonblock spec under 2.0
40957a3 Fix IO#read_nonblock spec under 2.0
fc0d729 Add a spec covering calling #instance_eval with a proc from a method
e32825a Added specs for RARRAY_AREF.
997fc93 Added spec for IO#write_nonblock raising
45dcbd1 Test IO#read_nonblock raising EAGAINWaitReadable
400a56f Fix a typo s/refering/referring/
c76d706 Fixed Dir.pwd spec with unicode characters.
0512054 Add spec about -> lambda scoping.
f0b6cf6 Accomodate for Thread#backtrace being nil when thread is not started yet.
7462ac9 BigDecimal.new raises ArgumentError when Float is used without precision
79f43c0 do not raise when precision is passed to BigDecimal#round
26ac864 Fix line in Exception#backtrace spec.
2269430 Move the fixture class to fixtures.
d799042 Merge pull request #178 from yuki24/add-spec-for-name-error-receiver
abee55f Merge pull request #177 from yuki24/add-specs-for-name-error-name
fc420f3 Add specs for NameError#name
c127124 Add more examples for NameError#receiver
b09e8fd Simplify a spec for NameError#receiver
674b32f Speficy that hidden metaclasses stay hidden.
7b99cfc Merge pull request #179 from yuki24/use-latest-rubies
0d96eb5 Use the latest rubies on Travis
2617339 Add spec for Symbol#to_proc plus Proc#parameters => [[:rest]]
bbcb689 Mask out specs+fixtures for keyreq added in 2.1.
df59b1f Add some simple specs for Method#parameters with keyword args.
bac69ca wait for the parent to read
4960e98 Revert "wait for the parent to read" because of stall on Solaris
822aac3 NetHTTPSpecs.start_server should not use hardcoded port number.
379401f Fix and complete Thread#name spec.
9912132 [ruby-2.3 core/thread] - Add specs for Thread#name and Thread#name=
ae8ef6a Explicitly state the relation between classes since this spec is meta-meta
1a31f57 Merge pull request #173 from nobu/bug/fd-passing-tests
652d332 wait for the parent to read
f60ee1e Merge pull request #172 from nobu/feature/dig_change
e34b1a4 separate TypeError cases on dig
7526c4e Merge pull request #171 from nobu/feature/dig_change
4d25005 dig method update
2f8577d Ruby 2.3 doesn't raise error
72b2688 Specify the behavior of Date#<< with respect to the version
f8358bd Merge pull request #170 from nobu/bug/Date-minus_month-exception
1fdd93d do not mind excepction class
53f535b Merge pull request #168 from cthulhua/chunk_while
f4ae8fc [ruby-2.3 core/enumerable] - Add specs for enumerable#chunk_while
1b726f7 Merge pull request #167 from nobu/bug/fix-infection-from-range
2a8f30a Fix version to ruby_bug
67fb1f7 Merge pull request #166 from nobu/bug/fix-infection-from-range
7198825 Fix infection from Range
e1b1ba6 Use the container infrastructure on Travis CI
5cec3a3 Fix UTF-8 Encoding constant name in StringIO specs
c330bfd Fix StringIO specs file structure
e148e90 Fix StringIO#isatty describe title
1f358a4 Fix location of ObjectSpace fixtures.

git-subtree-dir: spec/ruby
git-subtree-split: d9a07bfec7af8baef9daa85f2de9dcb9e18da170
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

4 participants