Fix Time.new when using (empty) keywords (2 issues)#8858
Merged
headius merged 2 commits intojruby:masterfrom Jun 23, 2025
Merged
Fix Time.new when using (empty) keywords (2 issues)#8858headius merged 2 commits intojruby:masterfrom
Time.new when using (empty) keywords (2 issues)#8858headius merged 2 commits intojruby:masterfrom
Conversation
Solves jruby#8854 Prevents `Time.new(2023, 2, 1, **{})` from raising NullPointerException when accessing `opts` which can happened when keyword args are empty, e.g: https://github.com/rails/rails/blob/v7.1.5.1/activesupport/lib/active_support/testing/time_helpers.rb#L185 Unsure if this is the best way, but it does the job for now I think. I realised that if keywords was empty, `hasKeywords` still returns true and `extractKeywordArgs` returns null, and `args` doesn't have the Hash object, it is just missing. So that is why we can only subtract 1 from argc after `extractKeywordArgs` and confirming it is not null. It feels there is a more general problem of how keywords are handled or/and a missing helper to avoid these issues as I think this bug may be in a couple more places in the codebase, but probably people don't hit them frequently. I added a test for it since it was a regression from JRuby v9, but also unsure where best to put the test or if it is something we want / need. Feel free to make any changes or suggestions.
Time.new when using (empty) keywords (2 issues)
Member
|
Hey sorry I missed this, it's been a busy month! Thanks so much for pitching in and fixing these issues! I'll review today and get it merged for future releases. |
Member
|
Looks good to me. Typical case of us not using new mechanism for detecting keywords. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8854 and #8860.
The
travel_totest helper from ActiveSupport triggers the empty keywords issue.As a result of fixing the NullPointerException and writing a regression test, it actually triggered the other issue of losing the last argument when using keywords.
I realised that if keywords was empty,
hasKeywordsstill returns true andextractKeywordArgsreturns null, andargsdoesn't have the Hash object, it is just missing. So that is why we can only subtract 1 from argc afterextractKeywordArgsand confirming it is not null. Also, since we are already subtracting one, then we don't need the keywords condition again in the argc switch.I added a test for it since it was a regression from JRuby v9.