Java class comparison asymmetry, lost to_java_object in 1.5

http://jira.codehaus.org/ is returning a 404 for me, so sending this
here first. Also please advise, is this best as one or two bugs?

Thanks for JRuby 1.5.0.RC1. It gave me pause to figure out:

  1. An apparent long standing asymmetry in java class comparison (which I
    had previously unwittingly worked around with to_java_object.)

  2. The JRuby method to_java_object is no longer exposed in JRuby
    1.5.0.RC1 (intended?)

Test code with comments below, followed by output:

Foo.java::

public class Foo {
public Class valueType()
{
return Integer.class;
}
}

test_java_class_object.rb::

#!/usr/bin/env jruby
#.hashdot.profile += jruby-shortlived

require ‘java’
require ‘test/unit’

class TestJavaClassObject < Test::Unit::TestCase
import ‘Foo’

Works in Jruby 1.4.0, 1.5.0.RC1!

def test_class_from_java_left
assert_equal( Foo.new.value_type, Java::java.lang.Integer.java_class
)
end

Fails in both Jruby 1.4.0, 1.5.0.RC1!

def test_class_from_java_right
assert_equal( Java::java.lang.Integer.java_class, Foo.new.value_type
)
end

The workaround was to use to_java_object, but this doesn’t exist in

Jruby 1.5.0.RC1:

def test_class_from_java_right_obj
assert_equal( Java::java.lang.Integer.java_class,
Foo.new.value_type.to_java_object )
end
end

% javac Foo.java
% jruby-1.4 ./test_java_class_object_2.rb
Loaded suite ./test_java_class_object_2
Started
.F.
Finished in 0.082 seconds.

  1. Failure:
    test_class_from_java_right(TestJavaClassObject)
    [./test_java_class_object_2.rb:17]:
    expected but was
    .

3 tests, 3 assertions, 1 failures, 0 errors

% jruby-1.5 ./test_java_class_object_2.rb
Loaded suite ./test_java_class_object_2
Started
.FE
Finished in 0.125 seconds.

  1. Failure:
    test_class_from_java_right(TestJavaClassObject)
    [./test_java_class_object_2.rb:17]:
    expected but was
    .

  2. Error:
    test_class_from_java_right_obj(TestJavaClassObject):
    NoMethodError: undefined method to_java_object' for class java.lang.Integer:Java::JavaLang::Class ./test_java_class_object_2.rb:23:in test_class_from_java_right_obj’

3 tests, 2 assertions, 1 failures, 1 errors

Hi David,

I think that it has been replaced by to_java() call. Try to use it and
see whether it works for you.

As a side note, we probably shouldn’t just remove public methods like
that and maybe to_java_object should just be an alias for to_java().
Hmm, I’ll check with Charlies.

Thanks,
–Vladimir

On Fri, Apr 16, 2010 at 3:41 AM, David K. [email protected]
wrote:

The workaround was to use to_java_object, but this doesn’t exist in

Started

.

  1. Error:
    test_class_from_java_right_obj(TestJavaClassObject):
    NoMethodError: undefined method to_java_object' for class java.lang.Integer:Java::JavaLang::Class ./test_java_class_object_2.rb:23:in test_class_from_java_right_obj’

3 tests, 2 assertions, 1 failures, 1 errors


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, 2010-04-16 at 08:08 +0200, Vladimir S. wrote:

Hi David,

I think that it has been replaced by to_java() call. Try to use it and
see whether it works for you.

If I make that substitution in the test code below, the method is found
only in 1.5, and then doesn’t suffice as a workaround for the problem
with that comparison order.

As a side note, we probably shouldn’t just remove public methods like
that and maybe to_java_object should just be an alias for to_java().
Hmm, I’ll check with Charlies.

Seems better yes, but note there is also some behavior change given
to_java not having the same effect as the old to_java_object.

Thanks,
David