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

Cannot subclass standard class Time #5125

Closed
bittrance opened this Issue Mar 29, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@bittrance

bittrance commented Mar 29, 2018

Because of some code that does not believe in duck typing, I need to subclass Time for testing purposes. This works fine in Ruby 2.4.2:

irb(main):001:0> class TT < Time ; def initialize(m, n) ; super(m) ; end ; end
=> :initialize
irb(main):002:0> TT.new(1, 2)
=> 0001-01-01 00:00:00 +0100

However, the same code fails in JRuby 9.1.13.0:

irb(main):004:0* class TT < Time ; def initialize(m, n) ; super(m) ; end ; end
=> :initialize
irb(main):005:0> TT.new(1, 2)
ArgumentError: wrong number of arguments (0 for 2)
	from (irb):5:in `initialize'
	from org/jruby/RubyTime.java:1252:in `new'
	from (irb):5:in `<eval>'
	from org/jruby/RubyKernel.java:994:in `eval'
	from org/jruby/RubyKernel.java:1292:in `loop'
	from org/jruby/RubyKernel.java:1114:in `catch'
	from org/jruby/RubyKernel.java:1114:in `catch'
	from .rbenv/versions/jruby-9.1.13.0/bin/irb:13:in `<main>'

Whereas providing an empty constructor works fine even in JRuby:

irb(main):001:0> class TT < Time ; def initialize ; super() ; end ; end
=> :initialize
irb(main):002:0> TT.new
=> 2018-03-30 01:07:33 +0200

Is this an obscure bug or have I misunderstood something?

Environment

jruby 9.1.13.0 (2.3.3) 2017-09-06 8e1c115 Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [darwin-x86_64]

@headius

This comment has been minimized.

Member

headius commented Apr 11, 2018

I'll bet on obscure bug 👍

@headius

This comment has been minimized.

Member

headius commented Apr 11, 2018

Yeah this is a long-standing issue where our Time class defines its own new rather than its own initialize, and that new attempts to call initialize with zero arguments always. I've been meaning to try to fix this, so I'll have another crack at it.

headius added a commit that referenced this issue Apr 11, 2018

@headius

This comment has been minimized.

Member

headius commented Apr 11, 2018

@bittrance I've pushed a fix for this to the jruby-9.1 branch, which can be found in the stable nightly build. Please let us know that it works for you.

@headius headius added this to the JRuby 9.1.17.0 milestone Apr 11, 2018

@headius headius closed this Apr 11, 2018

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