Skip to content

Comparing Date object with nil sets global $! variable to NoMethodError #6386

@amitsuryavanshi

Description

@amitsuryavanshi

Date.today.compare_with_coercion nil or Date.today <=> nil sets the ruby global variable $! to #<NoMethodError: undefined method coerce for nil:NilClass>. It does not throw the exception but sets the global $! variable. Now when I raise the exception in my app code the raised exception's cause is set to #<NoMethodError: undefined method coerce' for nil:NilClass>`.

Environment Information

  • JRuby version - jruby-9.2.13.0
  • Operating system - MaC OS Catalina
  • Rails - 6.0.3.2

Expected Behavior

  • Raise the exception #<NoMethodError: undefined method coerce for nil:NilClass> rather than just setting it in $!

Actual Behavior

  • Sets the ruby's $! variable to #<NoMethodError: undefined method coerce for nil:NilClass> but does not raises it.

Script

require 'rubygems'
require 'active_support'
require "date"

puts 'Before $! => '
puts  $!
Date.today <=> nil
puts 'After $! => '
puts  $!

Script Output :

Before $! => 

After $! => 
undefined method `coerce' for nil:NilClass

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