Skip to content

to_time raise an exception. (class org.jruby.ext.date.RubyDate cannot be cast to class org.jruby.ext.date.RubyDateTime) #8139

@hiroyuki-sato

Description

@hiroyuki-sato

Hello, members. Could someone tell me if this behavior is expected or not?
The Original developer(Sisimai See below) said. this behavior was introduced from JRuby 9.2.x.x. (Please see this link sisimai/rb-sisimai#159)

Best regards.

Environment Information

Provide at least:

  • JRuby version: jruby-9.4.3.0
  • Operating system: macOS 13.6.3 (m1)
  • Java version: OpenJDK 64-Bit Server VM Zulu17.42+19-CA (build 17.0.7+7-LTS, mixed mode, sharing)

Expected Behavior

  • MRI(Ruby 3.2.2) doesn't raise the exception.

Actual Behavior

  • JRuby raise the exception.
require 'date'
# miniimzed Sisimai::Time
module Sisimai
  class Time < ::DateTime
  end
end

datestring = 'Tue, 28 Apr 2009 09:52:45'
begin
  t = Sisimai::Time.strptime(datestring, '%a, %d %b %Y')
  t.to_time

rescue
  print $!
  print $!.backtrace.join("\n")
end
class org.jruby.ext.date.RubyDate cannot be cast to class org.jruby.ext.date.RubyDateTime (org.jruby.ext.date.RubyDate and org.jruby.ext.date.RubyDateTime are in module org.jruby.dist of loader 'app')org.jruby.dist/org.jruby.ext.date.RubyDateTime$INVOKER$i$0$0$to_time.call(RubyDateTime$INVOKER$i$0$0$to_time.gen)
org.jruby.dist/org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:456)
org.jruby.dist/org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:195)
test.invokeOther2:to_time(test.rb:11)
test.RUBY$script(test.rb:11)
test.run(test.rb)
java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
org.jruby.dist/org.jruby.ir.Compiler$1.load(Compiler.java:114)
org.jruby.dist/org.jruby.Ruby.runScript(Ruby.java:1276)
org.jruby.dist/org.jruby.Ruby.runNormally(Ruby.java:1193)
org.jruby.dist/org.jruby.Ruby.runNormally(Ruby.java:1175)
org.jruby.dist/org.jruby.Ruby.runNormally(Ruby.java:1211)
org.jruby.dist/org.jruby.Ruby.runFromMain(Ruby.java:989)
org.jruby.dist/org.jruby.Main.doRunFromMain(Main.java:398)
org.jruby.dist/org.jruby.Main.internalRun(Main.java:282)
org.jruby.dist/org.jruby.Main.run(Main.java:227)
org.jruby.dist/org.jruby.Main.main(Main.java:199)

Reference

sisimai/rb-sisimai#267

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions