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

Issue with object form constructor by reflection. #2595

Closed
blerins opened this Issue Feb 13, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@blerins
Copy link

blerins commented Feb 13, 2015

Hello,

According to this documentation: https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#constructors
I think this should work:

bruno@dexter:~/workspace/spike/jruby$ jruby --version
jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on OpenJDK 64-Bit Server VM 1.7.0_65-b32 +jit [linux-amd64]
bruno@dexter:~/workspace/spike/jruby$ irb
irb(main):001:0> c = java.awt.Color.java_class.constructor(Java::int, Java::int, Java::int)
=> Java::JavaConstructorint,int,int)>
irb(main):002:0> color = c.new_instance(10,10,10)
=> #<Java::JavaObject:0x3b625be>
irb(main):003:0> color.to_s
=> "java.awt.Color[r=10,g=10,b=10]"
irb(main):004:0> color.red
NoMethodError: undefined method `red' for #<Java::JavaObject:0x3b625be>
    from (irb):4:in `evaluate'
    from org/jruby/RubyKernel.java:1107:in `eval'
    from org/jruby/RubyKernel.java:1507:in `loop'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from /home/bruno/.rbenv/versions/jruby-1.7.19/bin/irb:13:in `(root)'
irb(main):005:0> color.getRed
NoMethodError: undefined method `getRed' for #<Java::JavaObject:0x3b625be>
    from (irb):5:in `evaluate'
    from org/jruby/RubyKernel.java:1107:in `eval'
    from org/jruby/RubyKernel.java:1507:in `loop'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from /home/bruno/.rbenv/versions/jruby-1.7.19/bin/irb:13:in `(root)'

Am I missing something?

Thanks!

@headius

This comment has been minimized.

Copy link
Member

headius commented Mar 12, 2015

Perhaps you can tell me what you're trying to accomplish? The JavaObject group of classes are largely not recommended and are being phased out. If you need to get at a specific constructor, there are other ways to do it (or we can add better ways).

@blerins

This comment has been minimized.

Copy link
Author

blerins commented Mar 12, 2015

I was trying to avoid this warning:

irb(main):002:0> java.awt.Color.new(10,10,10)
(irb):2 warning: ambiguous Java methods found, using java.awt.Color(int,int,int)
=> #<Java::JavaAwt::Color:0x4671115f>

@kares kares self-assigned this Mar 13, 2015

kares added a commit to kares/jruby that referenced this issue Mar 14, 2015

kares added a commit to kares/jruby that referenced this issue Mar 14, 2015

kares added a commit to kares/jruby that referenced this issue Mar 18, 2015

kares added a commit to kares/jruby that referenced this issue Mar 18, 2015

@kares

This comment has been minimized.

Copy link
Member

kares commented Mar 19, 2015

there's a fix for this on jruby-1_7 adeb887 it's not 100% perfect (generic) but also avoids a similar (BigInteger ambiguous method) warning that has been irritating on JRuby-OpenSSL for a while ...

@kares kares closed this Mar 19, 2015

@kares kares added this to the JRuby 1.7.20 milestone Mar 19, 2015

kares added a commit to kares/jruby that referenced this issue Mar 19, 2015

Merge branch 'jruby-1_7' into master
* jruby-1_7: (24 commits)
  calculate 'sofisticated' type preference when ambiguous callables found (fixes jruby#2595)
  in case there's an exact parameter match - do not proceed with argument matching
  do not do equals on Class objects (just compare by identity) + remove unused imports
  re-factored candidate matching loops - for more readability and less implicit iterator use
  cleanup the constructor search - keeping redundant ~ 'intended' code as comments
  a slight Java integration (mostly bootstrap internals) cleanup
  update CallableSelector's (Map) cache internals - so we can easily refactor further
  move Java.method_missing into native
  loadPaths list generics - easier to guess for JavaEmbedUtils consumers
  add a factory onto ClassValue since we're be instantiating the same (based on opt)
  one JRubyMethod with 2 names is enough to have
  more base-class sharing between JavaCallable method/constructor impl + minor tweaks
  move getArity/getParameterTypes into base class as finals + help used methods to JIT
  guess name-class hash-map size without internal resizing (currently <= 48 elements)
  after several concurrency fixes in Java integration - un-comment a multi-threaded test
  non need to cast intValue to (int)
  move (and tune) error logic from CallableSelector into the invoker impl where it's used
  align JavaField's value/static_value conversions and return values + test functionality
  correct (Java) equals/hashCode semantics for JavaAccessibleObject + minor tweaks
  Try turning off sudo:false to fix build issues.
  ...

Conflicts:
	.travis.yml
	core/src/main/java/org/jruby/RubyObject.java
	core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java
	core/src/main/java/org/jruby/javasupport/JavaCallable.java
	core/src/main/java/org/jruby/javasupport/JavaEmbedUtils.java
	core/src/main/java/org/jruby/javasupport/JavaSupport.java
	core/src/main/java/org/jruby/runtime/Helpers.java
	core/src/main/java/org/jruby/util/CodegenUtils.java
	core/src/main/ruby/jruby/java.rb
	core/src/test/java/org/jruby/test/TestCodeCache.java
	test/test_higher_javasupport.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.