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

Selecting a particular constructor by signature using reflection does not work #2413

Closed
dlbirch opened this issue Jan 3, 2015 · 4 comments
Closed

Comments

@dlbirch
Copy link

dlbirch commented Jan 3, 2015

I'm working with a popular (in the payments business) java library called jPOS (from the jPOS.org folks). Jpos.jar to be specific.

I'm unable to get a fully functional object when attempting to use one of the overloaded constructors on the ISOBinaryField class. Seems it will create the object but with none of the methods attached? For example, the class has a public 'toString' method that cannot be accessed? Here is my jirb for the details:

/Users/dbirch/jruby/versions/jruby-1.7.16/bin/jruby --2.0 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/dbirch/jruby/versions/jruby-1.7.16/bin/jirb --prompt simple
Switch to inspect mode.

require 'iso_binary_field'
=> true

?> >> require 'java'
=> false

?> >> require './lib/jpos.jar'
=> true

?> >> java_import org.jpos.iso.ISOBinaryField
=> [Java::OrgJposIso::ISOBinaryField]

?> >> construct = org.jpos.iso.ISOBinaryField.java_class.constructor(Java::int, Java::byte[], Java::int, Java::int)
=> Java::JavaConstructorint,[B,int,int)>

?> >> byte_array = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
=> [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]

?> >> jpos_ibf = construct.new_instance(2, byte_array, 0, 10)
=> #Java::JavaObject:0x7ba52267

?> >> jpos_ibf.java_class
=> class org.jpos.iso.ISOBinaryField

?> >> jpos_ibf.class
=> Java::JavaObject

?> ?> >> jpos_ibf.toString()
NoMethodError: undefined method toString' for #<Java::JavaObject:0x7ba52267> from (irb):45:inevaluate'
from org/jruby/RubyKernel.java:1101:in eval' from org/jruby/RubyKernel.java:1501:inloop'
from org/jruby/RubyKernel.java:1264:in catch' from org/jruby/RubyKernel.java:1264:incatch'
from /Users/dbirch/jruby/versions/jruby-1.7.16/bin/jirb:13:in (root)' from org/jruby/RubyKernel.java:1081:inload'
from -e:1:in `(root)'

@kares
Copy link
Member

kares commented May 23, 2017

require 'java'

require './jpos.jar'

java_import org.jpos.iso.ISOBinaryField

construct = org.jpos.iso.ISOBinaryField.java_class.constructor(Java::int, Java::byte[], Java::int, Java::int)

puts construct

byte_array = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]

jpos_ibf = construct.new_instance(2, byte_array, 0, 10)

puts jpos_ibf.java_class

puts jpos_ibf.toString()

still an issue on 9K ... probably should get rid of those wrappers once and for good - maybe in 9.2 !?

public org.jpos.iso.ISOBinaryField(int,byte[],int,int)
org.jpos.iso.ISOBinaryField
NoMethodError: undefined method `toString' for #<Java::JavaObject:0x704921a5>
  <main> at pos.rb:19

@kares kares added this to the JRuby 9.2.0.0 milestone May 23, 2017
@headius
Copy link
Member

headius commented May 16, 2018

@kares You added this...do you have a fix or perhaps fixed this? Otherwise, we should punt to 9.2.1 or remove milestone.

@kares
Copy link
Member

kares commented May 17, 2018

yeah, needs a rewrite. not sure I will manage this out as it would take me quite some time ... moving

@kares kares modified the milestones: JRuby 9.2.0.0, JRuby 9.2.1.0 May 17, 2018
@headius
Copy link
Member

headius commented Sep 19, 2018

This is now very old, and with no follow-up from the author I'm going to close it.

The JavaClass, JavaObject etc API has been unofficially deprecated for some time, so I would encourage @dlbirch to work with us to figure out the blessed way to do what he needs here, if it doesn't "just work" due to JI fixes we've made over the years.

As for getting rid of those wrappers...we get closer all the time, but there's lots of unusual functionality that's hard to provide on the "real" java.lang.Class and friends. It will happen slowly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants