Exemple #1
0
  public void testRubyExceptionBacktraceIncludesJavaOrigin() throws Exception {
    String script =
        "require 'java'\n"
            + "hash = Hash.new { org.jruby.test.TestRaiseException::ThrowFromJava.new.throwIt }\n"
            + "begin; hash['missing']; rescue java.lang.Exception => e; $ex_trace = e.backtrace end \n"
            + "$ex_trace";

    RubyArray trace = (RubyArray) runtime.evalScriptlet(script);

    String fullTrace = trace.join(runtime.getCurrentContext(), runtime.newString("\n")).toString();
    // System.out.println(fullTrace);

    // NOTE: 'unknown' JRuby packages e.g. "org.jruby.test" should not be filtered
    //  ... if they are that hurts stack-traces from extensions such as jruby-rack and jruby-openssl
    assertTrue(
        trace.get(0).toString(),
        trace
            .get(0)
            .toString()
            .startsWith("org.jruby.test.TestRaiseException$ThrowFromJava.throwIt"));

    boolean hash_default = false;
    for (Object element : trace) {
      if (element.toString().contains("org.jruby.RubyHash.default")) {
        if (hash_default) fail("duplicate " + element + " in : \n" + fullTrace);
        hash_default = true;
      }
    }
    assertTrue("missing org.jruby.RubyHash.default ... in : \n" + fullTrace, hash_default);
  }