pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/63eefe64aeb7551bd5c4a72f8f20cda314cf97a6

" /> Do not rescue java.lang.Error using StandardError · jruby/jruby@63eefe6 · GitHub
Skip to content

Commit 63eefe6

Browse files
committed
Do not rescue java.lang.Error using StandardError
This in effect injects java.lang.Error as a subclass of Ruby Exception, instead of StandardError as was previously the case. This fixes #1696
1 parent 6fad586 commit 63eefe6

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

core/src/main/java/org/jruby/RubyException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyO
196196

197197
Object object = ((ConcreteJavaProxy)other).getObject();
198198
if (object instanceof Throwable && !(object instanceof FlowControlException)) {
199-
return context.runtime.getTrue();
199+
if (recv == runtime.getException() || object instanceof Exception) {
200+
return context.runtime.getTrue();
201+
}
200202
}
201203
}
202204
// fall back on default logic

spec/java_integration/exceptions/rescue_spec.rb

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,68 @@
44
java_import "java_integration.fixtures.ThrowExceptionInInitializer"
55
java_import "java_integration.fixtures.ExceptionRunner"
66

7-
describe "A non-wrapped Java throwable" do
7+
describe "A non-wrapped Java error" do
88
it "can be rescued using the Java type" do
99
exception = OutOfMemoryError.new
1010
begin
1111
raise exception
1212
rescue OutOfMemoryError => oome
1313
end
14-
15-
oome.should_not == nil
14+
1615
oome.should == exception
1716
end
1817

18+
it "can be rescued using Object" do
19+
begin
20+
raise OutOfMemoryError.new
21+
rescue Object => e
22+
e.should be_kind_of(OutOfMemoryError)
23+
end
24+
end
25+
26+
it "can be rescued using Exception" do
27+
exception = OutOfMemoryError.new
28+
begin
29+
raise exception
30+
rescue Exception => e
31+
end
32+
33+
e.should == exception
34+
end
35+
36+
it "cannot be rescued using StandardError" do
37+
exception = OutOfMemoryError.new
38+
lambda do
39+
begin
40+
raise exception
41+
rescue => e
42+
end
43+
end.should raise_error(exception)
44+
end
45+
46+
it "cannot be rescued inline" do
47+
obj = Object.new
48+
def obj.go
49+
raise OutOfMemoryError.new
50+
end
51+
52+
lambda do
53+
obj.go rescue 'foo'
54+
end.should raise_error(OutOfMemoryError)
55+
end
56+
end
57+
58+
describe "A non-wrapped Java exception" do
59+
it "can be rescued using the Java type" do
60+
exception = java.lang.NullPointerException.new
61+
begin
62+
raise exception
63+
rescue java.lang.NullPointerException => npe
64+
end
65+
66+
npe.should == exception
67+
end
68+
1969
it "can be rescued using Object" do
2070
begin
2171
raise java.lang.NullPointerException.new

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy