-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
If a java.lang.NullPointerException is raised from inside a Proc, its stack trace gets printed out even if the exception is successfully rescued from Ruby. This might apply to other Java exceptions too. I would expect that these exceptions can be silently caught without printing stuff to the console; is that right? They can be silently caught if the Proc is not involved, so that makes me think this is a bug.
I was able to reproduce this problem in JRuby 1.7.10 on both Windows and Linux. Below is some shell output showing my version of JRuby and reproducing the problem:
$ jruby -v -e "proc{ raise java.lang.NullPointerException.new }.call rescue nil; puts 'hi'"
jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_45-b18 [Windows 8-amd64]
java.lang.NullPointerException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.jruby.javasupport.JavaConstructor.newInstanceDirect(JavaConstructor.java:259)
at org.jruby.java.invokers.ConstructorInvoker.call(ConstructorInvoker.java:79)
at org.jruby.java.invokers.ConstructorInvoker.call(ConstructorInvoker.java:160)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:316)
at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:145)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:149)
at org.jruby.java.proxies.ConcreteJavaProxy$2.call(ConcreteJavaProxy.java:48)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:316)
at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:145)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:149)
at org.jruby.RubyClass.newInstance(RubyClass.java:797)
at org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)
at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZeroOrNBlock.call(JavaMethod.java:280)
at org.jruby.java.proxies.ConcreteJavaProxy$3.call(ConcreteJavaProxy.java:141)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:306)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:136)
at ruby.__dash_e__.block_0$RUBY$__file__(-e:1)
at ruby$__dash_e__$block_0$RUBY$__file__.call(ruby$__dash_e__$block_0$RUBY$__file__)
at org.jruby.runtime.CompiledBlock19.yield(CompiledBlock19.java:159)
at org.jruby.runtime.CompiledBlock19.call(CompiledBlock19.java:87)
at org.jruby.runtime.Block.call(Block.java:101)
at org.jruby.RubyProc.call(RubyProc.java:290)
at org.jruby.RubyProc.call19(RubyProc.java:271)
at org.jruby.RubyProc$INVOKER$i$0$0$call19.call(RubyProc$INVOKER$i$0$0$call19.gen)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:202)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:198)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:306)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:136)
at ruby.__dash_e__.chained_0_rescue_1$RUBY$SYNTHETIC__file__(-e)
at ruby.__dash_e__.__file__(-e:1)
at ruby.__dash_e__.load(-e)
at org.jruby.Ruby.runScript(Ruby.java:811)
at org.jruby.Ruby.runScript(Ruby.java:804)
at org.jruby.Ruby.runNormally(Ruby.java:673)
at org.jruby.Ruby.runFromMain(Ruby.java:522)
at org.jruby.Main.doRunFromMain(Main.java:395)
at org.jruby.Main.internalRun(Main.java:290)
at org.jruby.Main.run(Main.java:217)
at org.jruby.Main.main(Main.java:197)
hi
You can see that the exception was successfully caught because the word "hi" got printed at the end. However, some part of the system still printed a stack trace to the console.
The reason I found this is because I am on the jruby-1_7 branch and have almost cleaned up all the warnings that get printed for me when running rake spec:ji:int. However, a big Java stack trace gets printed out when spec/java_integration/extensions/kernel_spec.rb runs.