JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6791

RuntimExceptions with a Ruby Exception as cause will not print out complete stacktrace

    Details

    • Number of attachments :
      0

      Description

      When a Ruby Exception is wrapped within a RuntimeException and is being printed by the default root exception handler, the stacktrace elements from the ruby exception is missing.

      See the example: git://github.com/retoo/wrapped_stacktrace.git

      Interestingly log4j.log("msg", exception) prints out the full stacktrace.

      Thanks!
      Reto Schüttel

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        I'm a little confused by this one.

        I see that your test code eventually rethrows a RuntimeException wrapping the Ruby exception, but in my output the last dump of stack traces does include the cause and does show the Ruby trace.

        Perhaps you can show me your output annotated with information about what you'd expect to see? Or perhaps write this in the form of a test case that fails?

        Show
        Charles Oliver Nutter added a comment - I'm a little confused by this one. I see that your test code eventually rethrows a RuntimeException wrapping the Ruby exception, but in my output the last dump of stack traces does include the cause and does show the Ruby trace. Perhaps you can show me your output annotated with information about what you'd expect to see? Or perhaps write this in the form of a test case that fails?
        Hide
        Reto Schüttel added a comment - - edited

        I've de-cluttered the example.

        My output is, please get a the newer version from the git repo.

        NativeException: java.lang.RuntimeException: org.jruby.exceptions.RaiseException: (RuntimeError) here be exceptions
               someJavaMethod at com/example/Test.java:30
                    invoke_L1 at java/lang/invoke/MethodHandleImpl.java:1122
          invokeWithArguments at java/lang/invoke/MethodHandle.java:566
                       (root) at excepion.rb:25
                       (root) at excepion.rb:25
        
        Show
        Reto Schüttel added a comment - - edited I've de-cluttered the example. My output is, please get a the newer version from the git repo. NativeException: java.lang.RuntimeException: org.jruby.exceptions.RaiseException: (RuntimeError) here be exceptions someJavaMethod at com/example/Test.java:30 invoke_L1 at java/lang/invoke/MethodHandleImpl.java:1122 invokeWithArguments at java/lang/invoke/MethodHandle.java:566 (root) at excepion.rb:25 (root) at excepion.rb:25
        Hide
        Charles Oliver Nutter added a comment -

        Maybe I'm still misunderstanding, but my output from cloning, building, and running your "excepion.rb" includes the Java trace of the RuntimeException and the Ruby trace of the RuntimeError. What's missing here?

        system ~/projects/jruby/tmp/wrapped_stacktrace $ jruby --1.9 -J-cp ~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar excepion.rb 
        Test.java:30:in `someJavaMethod': java.lang.RuntimeException: org.jruby.exceptions.RaiseException: (RuntimeError) here be exceptions
        	from NativeMethodAccessorImpl.java:-2:in `invoke0'
        	from NativeMethodAccessorImpl.java:39:in `invoke'
        	from DelegatingMethodAccessorImpl.java:25:in `invoke'
        	from Method.java:597:in `invoke'
        	from JavaMethod.java:455:in `invokeDirectWithExceptionHandling'
        	from JavaMethod.java:367:in `invokeStaticDirect'
        	from StaticMethodInvoker.java:58:in `call'
        	from CachingCallSite.java:312:in `cacheAndCall'
        	from CachingCallSite.java:169:in `call'
        	from excepion.rb:25:in `__file__'
        	from excepion.rb:-1:in `load'
        	from Ruby.java:778:in `runScript'
        	from Ruby.java:771:in `runScript'
        	from Ruby.java:648:in `runNormally'
        	from Ruby.java:497:in `runFromMain'
        	from Main.java:376:in `doRunFromMain'
        	from Main.java:265:in `internalRun'
        	from Main.java:231:in `run'
        	from Main.java:215:in `run'
        	from Main.java:195:in `main'
        Caused by:
        excepion.rb:18:in `yet_another_method': org.jruby.exceptions.RaiseException: (RuntimeError) here be exceptions
        	from excepion.rb:14:in `some_other_method'
        	from excepion.rb:10:in `doTheCallBack'
        	from org/jruby/gen/InterfaceImpl864400492.gen:13:in `doTheCallBack'
        	from excepion.rb:25:in `(root)'
        
        Show
        Charles Oliver Nutter added a comment - Maybe I'm still misunderstanding, but my output from cloning, building, and running your "excepion.rb" includes the Java trace of the RuntimeException and the Ruby trace of the RuntimeError. What's missing here? system ~/projects/jruby/tmp/wrapped_stacktrace $ jruby --1.9 -J-cp ~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar excepion.rb Test.java:30:in `someJavaMethod': java.lang.RuntimeException: org.jruby.exceptions.RaiseException: (RuntimeError) here be exceptions from NativeMethodAccessorImpl.java:-2:in `invoke0' from NativeMethodAccessorImpl.java:39:in `invoke' from DelegatingMethodAccessorImpl.java:25:in `invoke' from Method.java:597:in `invoke' from JavaMethod.java:455:in `invokeDirectWithExceptionHandling' from JavaMethod.java:367:in `invokeStaticDirect' from StaticMethodInvoker.java:58:in `call' from CachingCallSite.java:312:in `cacheAndCall' from CachingCallSite.java:169:in `call' from excepion.rb:25:in `__file__' from excepion.rb:-1:in `load' from Ruby.java:778:in `runScript' from Ruby.java:771:in `runScript' from Ruby.java:648:in `runNormally' from Ruby.java:497:in `runFromMain' from Main.java:376:in `doRunFromMain' from Main.java:265:in `internalRun' from Main.java:231:in `run' from Main.java:215:in `run' from Main.java:195:in `main' Caused by: excepion.rb:18:in `yet_another_method': org.jruby.exceptions.RaiseException: (RuntimeError) here be exceptions from excepion.rb:14:in `some_other_method' from excepion.rb:10:in `doTheCallBack' from org/jruby/gen/InterfaceImpl864400492.gen:13:in `doTheCallBack' from excepion.rb:25:in `(root)'
        Hide
        Reto Schüttel added a comment -

        hmm.. yours looks perfect. But it doesn't work here. Strange... I've got a freshly cleaned and built jruby, directly from the unchanged origin/master. I'll check again with a different environment. Thanks for looking into it.

        Show
        Reto Schüttel added a comment - hmm.. yours looks perfect. But it doesn't work here. Strange... I've got a freshly cleaned and built jruby, directly from the unchanged origin/master. I'll check again with a different environment. Thanks for looking into it.
        Hide
        Charles Oliver Nutter added a comment -

        Ok, Reto discovered that while it does indeed work properly on Java 6, it does not on Java 7, and I just confirmed that. I also confirmed that turning off invokedynamic fixes it...so I would guess there's something about how we're doing the Java dispatch that's messing up the wrapped exception.

        Reopening.

        Show
        Charles Oliver Nutter added a comment - Ok, Reto discovered that while it does indeed work properly on Java 6, it does not on Java 7, and I just confirmed that. I also confirmed that turning off invokedynamic fixes it...so I would guess there's something about how we're doing the Java dispatch that's messing up the wrapped exception. Reopening.
        Hide
        Charles Oliver Nutter added a comment -

        Simple fix...indy dispatch was still wrapping exceptions in NativeException.

        commit 16d6869928c20a20344deef9a42f7688731ff29e
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Thu Jul 26 11:35:24 2012 -0500
        
            Fix JRUBY-6791
            
            RuntimExceptions with a Ruby Exception as cause will not print out complete stacktrace
            
            InvokeDynamic-based call paths were still wrapping Java exceptions
            in NativeException. Removed that logic.
        
        :100644 100644 f0df83e... 6e7d123... M	src/org/jruby/runtime/invokedynamic/InvocationLinker.java
        
        Show
        Charles Oliver Nutter added a comment - Simple fix...indy dispatch was still wrapping exceptions in NativeException. commit 16d6869928c20a20344deef9a42f7688731ff29e Author: Charles Oliver Nutter <headius@headius.com> Date: Thu Jul 26 11:35:24 2012 -0500 Fix JRUBY-6791 RuntimExceptions with a Ruby Exception as cause will not print out complete stacktrace InvokeDynamic-based call paths were still wrapping Java exceptions in NativeException. Removed that logic. :100644 100644 f0df83e... 6e7d123... M src/org/jruby/runtime/invokedynamic/InvocationLinker.java
        Hide
        Reto Schüttel added a comment -

        I created a followup Issue on Github:

        https://github.com/jruby/jruby/issues/1504

        This change made normal stacktraces worse.

        Show
        Reto Schüttel added a comment - I created a followup Issue on Github: https://github.com/jruby/jruby/issues/1504 This change made normal stacktraces worse.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Reto Schüttel
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: