Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Not A Bug
-
Affects Version/s: JRuby 1.7.0.pre1
-
Fix Version/s: None
-
Component/s: Core Classes/Modules
-
Labels:None
-
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]
-
Number of attachments :
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.
Activity
Hiro Asari
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Assignee | Hiro Asari [ asari ] | |
| Resolution | Not A Bug [ 6 ] |
Charles Oliver Nutter
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |