Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8942235d2b1e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ceb199a1416b
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Oct 23, 2014

  1. Copy the full SHA
    d3d8355 View commit details
  2. Fixed spacing

    pabloatplumbee committed Oct 23, 2014
    Copy the full SHA
    1bb4722 View commit details

Commits on Nov 2, 2014

  1. Merge pull request #2068 from pabloatplumbee/jruby-1_7

    Made Exception#set_backtrace compliant with Ruby documentation
    headius committed Nov 2, 2014
    Copy the full SHA
    ceb199a View commit details
Showing with 35 additions and 27 deletions.
  1. +14 −14 core/src/main/java/org/jruby/RubyException.java
  2. +21 −13 core/src/test/java/org/jruby/test/TestRubyException.java
28 changes: 14 additions & 14 deletions core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
@@ -36,29 +36,26 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jruby.runtime.backtrace.BacktraceData;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;

import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.JumpException.FlowControlException;
import org.jruby.java.proxies.ConcreteJavaProxy;
import org.jruby.runtime.Block;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ObjectMarshal;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.*;
import org.jruby.runtime.backtrace.BacktraceData;
import org.jruby.runtime.backtrace.RubyStackTraceElement;
import org.jruby.runtime.backtrace.TraceType;
import static org.jruby.runtime.Visibility.*;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.builtin.Variable;
import org.jruby.runtime.component.VariableEntry;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;

import java.io.IOException;
import java.io.PrintStream;
import java.util.List;

import static org.jruby.runtime.Visibility.PRIVATE;

/**
*
* @author jpetersen
@@ -91,11 +88,14 @@ public IRubyObject backtrace() {
public IRubyObject set_backtrace(IRubyObject obj) {
if (obj.isNil()) {
backtrace = null;
} else if (!isArrayOfStrings(obj)) {
throw getRuntime().newTypeError("backtrace must be Array of String");
} else {
} else if (isArrayOfStrings(obj)) {
backtrace = obj;
} else if (obj instanceof RubyString) {
backtrace = RubyArray.newArray(getRuntime(), obj);
} else {
throw getRuntime().newTypeError("backtrace must be Array of String or a single String");
}

return backtrace();
}

34 changes: 21 additions & 13 deletions core/src/test/java/org/jruby/test/TestRubyException.java
Original file line number Diff line number Diff line change
@@ -27,18 +27,17 @@
***** END LICENSE BLOCK *****/
package org.jruby.test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyException;
import org.jruby.RubyString;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

public class TestRubyException extends TestCase {

private Ruby interpreter;
@@ -53,29 +52,38 @@ public void testPrintBacktrace() throws Exception {
setBackTrace(18);

String[] lines = printError();
assertEquals(expectedTraceLine(1), lines[0]);
assertEquals(expectedTraceLine(RubyException.TRACE_HEAD + 1), lines[RubyException.TRACE_HEAD]);

assertEquals(expectedTraceLine(0), lines[0]);
assertEquals(expectedTraceLine(RubyException.TRACE_HEAD), lines[RubyException.TRACE_HEAD]);
}

public void testPrintNilBacktrace() throws Exception {
exception.set_backtrace(interpreter.getNil());
exception.set_backtrace(interpreter.getNil());

String[] lines = printError();

assertEquals(0, lines.length);
}

public void testPrintBackTraceWithString() throws Exception {
exception.set_backtrace(RubyArray.newArray(interpreter, RubyString.newString(interpreter, testLine(0))));

String[] lines = printError();

assertEquals(1, lines.length);
assertEquals(expectedTraceLine(0), lines[0]);
}

private String[] printError() {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(2048);
PrintStream stream = new PrintStream(byteArrayOutputStream);
exception.printBacktrace(stream, 1);
exception.printBacktrace(stream);
String output = new String(byteArrayOutputStream.toByteArray());
if (output.trim().length() == 0) {
return new String[0];
} else {
} else {
return output.split("\n");
}
}
}

private void setBackTrace(int lineCount) {