Lost implicit conversion from ruby Time to java.util.Date ---------------------------------------------------------
Key: JRUBY-4784 URL: http://jira.codehaus.org/browse/JRUBY-4784 Project: JRuby Issue Type: Bug Components: Java Integration Affects Versions: JRuby 1.5.0.RC2, JRuby 1.5 Environment: jruby 1.5.0.RC3 (ruby 1.8.7 patchlevel 249) (2010-05-04 603f15a) (Java HotSpot(TM) Client VM 1.6.0_19) [i386-java] Reporter: David Kellum Attachments: test_ruby_time_to_java.rb, TypeCheck.java JRuby 1.2.x,1.4.x, through 1.5.0.RC1 performed an implicit conversion of Ruby Time to java.util.Date, when calling a Java method which takes java.lang.Object. This behavior was lost between 1.5.0.RC1 and 1.5.0.RC2 and is still absent in RC3. Note that this conversion is still performed correctly in all versions when the Java method takes a java.util.Date instead of java.util.Object. Here is the test code (also attached): {code:java} public class TypeCheck { public static String className( Object o ) { return o.getClass().getName(); } } {code} {noformat} #!/usr/bin/env jruby #.hashdot.profile += jruby-shortlived require 'java' require 'test/unit' class TestRubyTimeToJava < Test::Unit::TestCase import 'TypeCheck' def test_type_object assert_equal( 'java.util.Date', TypeCheck::class_name( Time.now ) ) end import 'java.text.SimpleDateFormat' def test_type_date assert_equal( Time.now.year.to_s, SimpleDateFormat.new( "yyyy" ).format( Time.now ) ) end end {noformat} And here is the output for various versions: {noformat} % javac TypeCheck.java % jruby-1.4 -wv ./test_ruby_time_to_java.rb jruby 1.4.1 (ruby 1.8.7 patchlevel 174) (2010-04-26 ea6db6a) (Java HotSpot(TM) Client VM 1.6.0_19) [i386-java] Loaded suite ./test_ruby_time_to_java Started .. Finished in 0.017 seconds. 2 tests, 2 assertions, 0 failures, 0 errors % jruby-1.5.0.RC1 -wv ./test_ruby_time_to_java.rb jruby 1.5.0.RC1 (ruby 1.8.7 patchlevel 249) (2010-04-14 0b08bc7) (Java HotSpot(TM) Client VM 1.6.0_19) [i386-java] Loaded suite ./test_ruby_time_to_java Started ./test_ruby_time_to_java.rb:18 warning: multiple Java methods found for argument types ([String]): [public java.text.SimpleDateFormat(java.lang.String)] ./test_ruby_time_to_java.rb:18 warning: multiple Java methods found for argument types ([Time]): [public final java.lang.String java.text.DateFormat.format(java.util.Date), public final java.lang.String java.text.Format.format(java.lang.Object)] .. Finished in 0.019 seconds. 2 tests, 2 assertions, 0 failures, 0 errors % jruby-1.5.0.RC3 -wv ./test_ruby_time_to_java.rb jruby 1.5.0.RC3 (ruby 1.8.7 patchlevel 249) (2010-05-04 603f15a) (Java HotSpot(TM) Client VM 1.6.0_19) [i386-java] Loaded suite ./test_ruby_time_to_java Started .F Finished in 0.109 seconds. 1) Failure: test_type_object(TestRubyTimeToJava) [./test_ruby_time_to_java.rb:12]: <"java.util.Date"> expected but was <"org.jruby.RubyTime">. 2 tests, 2 assertions, 1 failures, 0 errors {noformat} -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email