Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreadable stacktraces when exceptions occur within Java code #1504

Closed
retoo opened this Issue Feb 13, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@retoo
Copy link
Contributor

retoo commented Feb 13, 2014

The Ruby part of stack traces is completely unusable if an error occurs within Java Code.

I was able to track down the change to the commit: 16d6869 which itself links to the JIRA issue JRUBY-6791 which was reported by me two years ago.

With -X+C the stack traces are a tad better (see below), with -X-C the stack traces are completely useless (not shown).

I'd love to see way to both support JRUBY-6791 and the old stacktraces. This is one of the biggest day to day pains these days with JRuby.

Thanks a lot!

Example Code

require 'java'
def test
  com.test.TestClass.new.foo
end

test
package com.test;

public class TestClass {
    public void foo() {
        throw new RuntimeException("why?");
    }
}

Before

Stacktrace before 16d6869.

    NativeException: java.lang.RuntimeException: why?
                      foo at com/test/TestClass.java:5
      invokeWithArguments at java/lang/invoke/MethodHandle.java:599
                     that at foo.rb:3
                     that at foo.rb:3
      invokeWithArguments at java/lang/invoke/MethodHandle.java:599
                       is at foo.rb:7
                       is at foo.rb:7
      invokeWithArguments at java/lang/invoke/MethodHandle.java:599
                   really at foo.rb:11
                   really at foo.rb:11
      invokeWithArguments at java/lang/invoke/MethodHandle.java:599
              unfortunate at foo.rb:15
              unfortunate at foo.rb:15
      invokeWithArguments at java/lang/invoke/MethodHandle.java:599
                   (root) at foo.rb:18
                   (root) at foo.rb:18

After

Stacktrace with 16d6869 and later.

    TestClass.java:5:in `foo': java.lang.RuntimeException: why?
        from MethodHandle.java:599:in `invokeWithArguments'
        from InvocationLinker.java:149:in `invocationFallback'
        from foo.rb:3:in `method__0$RUBY$that'
        from MethodHandle.java:599:in `invokeWithArguments'
        from InvocationLinker.java:149:in `invocationFallback'
        from foo.rb:7:in `method__1$RUBY$is'
        from MethodHandle.java:599:in `invokeWithArguments'
        from InvocationLinker.java:149:in `invocationFallback'
        from foo.rb:11:in `method__2$RUBY$really'
        from MethodHandle.java:599:in `invokeWithArguments'
        from InvocationLinker.java:149:in `invocationFallback'
        from foo.rb:15:in `method__3$RUBY$unfortunate'
        from MethodHandle.java:599:in `invokeWithArguments'
        from InvocationLinker.java:149:in `invocationFallback'
        from foo.rb:18:in `__file__'
        from foo.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'
@retoo

This comment has been minimized.

Copy link
Contributor Author

retoo commented Feb 13, 2014

Thanks for the help headius, the following option (available from 1.7.10) solves this problem:

jruby -Xrewrite.java.trace=true
com/test/TestClass.java:5:in `foo': java.lang.RuntimeException: why?
    from java/lang/reflect/Method.java:606:in `invoke'
    from foo.rb:3:in `that'
    from foo.rb:3:in `that'
    from foo.rb:7:in `is'
    from foo.rb:7:in `is'
    from foo.rb:11:in `really'
    from foo.rb:11:in `really'
    from foo.rb:15:in `unfortunate'
    from foo.rb:15:in `unfortunate'
    from foo.rb:18:in `(root)'
    from foo.rb:18:in `(root)'

@retoo retoo closed this Feb 13, 2014

headius added a commit that referenced this issue Feb 13, 2014

Rewrite Ruby parts of Java exceptions raised from JI calls.
This flag was added for #1313 but not turned on. Due to continued
reports from people having trouble interpreting JI stack traces,
we have decided to do this transformation by default.

Specifying -Xrewrite.java.trace=false or
-Djruby.rewrite.java.trace=false will return to the old non-
rewriting behvaior.

See #1504 and #1313 at least. Fixes #1504.

@enebo enebo added this to the JRuby 1.7.11 milestone Feb 21, 2014

@peter-ryan

This comment has been minimized.

Copy link

peter-ryan commented Jun 11, 2014

Is there a reason that the stack trace is duplicated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.