Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0.pre1
Assignee: Unassigned
Components: Core Classes/Modules
Created: 30/May/12 1:25 PM
Description:

It seems JRuby is the victim of bad documentation again. This time it's the Exception#== method which says, "If obj is not an Exception, returns false." Except that statement is false.

Based on the source code in error.c (lines 705 ff.) the obj can, in fact, be something other than an Exception IF it implements the :message and :backtrace methods AND they are each equal to the receiver's :message and :backtrace methods. Here is some sample code that demonstrates it:

# Note that this isn't a subclass of Exception!
class TestError
  attr_accessor :message

  def initialize(msg = nil)
    @message = msg
    @backtrace = nil
  end

  def set_backtrace(msg)
    @backtrace = msg
  end

  def backtrace
    @backtrace ? [@backtrace] : nil
  end
end

error1 = Exception.new
error2 = StandardError.new
error3 = TestError.new

p error1 == error1 # true
p error1 == error2 # false
p error1 == error3 # true in MRI, false in JRuby

Personally I don't really understand why MRI chose to do this, but there you have it.

Courtesy of berger_spec.

Environment: jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
Project: JRuby
Priority: Minor Minor
Reporter: Daniel Berger
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
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

Reply via email to