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: 79fd722e45b7
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c848f280e4b6
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Sep 30, 2016

  1. Fix JI test expecting NativeException-wrapping from constructors.

    In 5d057d2 I modified behavior for Java constructors by
    re-raising rather than wrapping in NativeException any exceptions
    they throw. The NativeException behavior was a relic of a bygone
    era, and normal Java methods have not thrown it for several years.
    This commit fixes a test that still expected all constructor-
    originated exceptions to be wrapped in NativeException; it now
    expects the true exception to be raised and asserts accordingly.
    headius committed Sep 30, 2016
    4
    Copy the full SHA
    3ee8ac9 View commit details
  2. Re-expose and deprecate RubyException.message.

    This field is still used by Psych (ruby/psych##292). I re-exposed
    it for now but modified all of JRuby to use the accessors so we
    aren't getting deprecation warnings. Once the gem is out we can
    attempt to hide the field again.
    headius committed Sep 30, 2016
    Copy the full SHA
    c848f28 View commit details
14 changes: 11 additions & 3 deletions core/src/main/java/org/jruby/NativeException.java
Original file line number Diff line number Diff line change
@@ -168,13 +168,21 @@ public void trimStackTrace(Member target) {

@Override
public final IRubyObject getMessage() {
IRubyObject message = super.getMessage();

if (message == null) {
if (messageAsJavaString == null) {
return message = getRuntime().getNil();
message = getRuntime().getNil();
} else {
message = getRuntime().newString(messageAsJavaString);
}
return message = getRuntime().newString(messageAsJavaString);

setMessage(message);

return message;
}
return message;

return super.getMessage();
}

@Override
13 changes: 7 additions & 6 deletions core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
@@ -272,12 +272,12 @@ public void initBacktrace() {
}

@Override
@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
public void copySpecialInstanceVariables(IRubyObject clone) {
RubyException exception = (RubyException)clone;
exception.backtraceData = backtraceData;
exception.backtrace = backtrace;
exception.message = message;
exception.setMessage(getMessage());
}

/**
@@ -392,7 +392,7 @@ public static IRubyObject newException(ThreadContext context, RubyClass exceptio
/**
* @return error message if provided or nil
*/
@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
public IRubyObject getMessage() {
return message == null ? getRuntime().getNil() : message;
}
@@ -401,7 +401,7 @@ public IRubyObject getMessage() {
* Set the message for this NameError.
* @param message the message
*/
@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
public void setMessage(IRubyObject message) {
this.message = message;
}
@@ -413,8 +413,9 @@ public String getMessageAsJavaString() {

private BacktraceData backtraceData;
private IRubyObject backtrace;
IRubyObject message;
IRubyObject cause;
@Deprecated
public IRubyObject message;
protected IRubyObject cause;

public static final int TRACE_HEAD = 8;
public static final int TRACE_TAIL = 4;
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyNameError.java
Original file line number Diff line number Diff line change
@@ -218,8 +218,8 @@ static RubyException newNameError(IRubyObject recv, IRubyObject message, IRubyOb
@JRubyMethod(rest = true, visibility = Visibility.PRIVATE)
@Override
public IRubyObject initialize(IRubyObject[] args, Block block) {
if ( args.length > 0 ) this.message = args[0];
if (message instanceof RubyNameErrorMessage) this.receiver = ((RubyNameErrorMessage) message).object;
if ( args.length > 0 ) this.setMessage(args[0]);
if (getMessage() instanceof RubyNameErrorMessage) this.receiver = ((RubyNameErrorMessage) getMessage()).object;
if ( args.length > 1 ) this.name = args[1];
else this.name = getRuntime().getNil();
super.initialize(NULL_ARRAY, block); // message already set
@@ -229,12 +229,12 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {
@JRubyMethod
@Override
public IRubyObject to_s(ThreadContext context) {
if (message.isNil()) {
if (getMessage().isNil()) {
return context.runtime.newString(getMetaClass().getRealClass().getName());
}
RubyString str = message.convertToString();
if (str != message) message = str;
return message;
RubyString str = getMessage().convertToString();
if (str != getMessage()) setMessage(str);
return getMessage();
}

@JRubyMethod
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubySystemCallError.java
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ public void marshalTo(Ruby runtime, Object obj, RubyClass type,

List<Variable<Object>> attrs = exc.getVariableList();
attrs.add(new VariableEntry<Object>(
"mesg", exc.message == null ? runtime.getNil() : exc.message));
"mesg", exc.getMessage() == null ? runtime.getNil() : exc.getMessage()));
attrs.add(new VariableEntry<Object>("errno", exc.errno));
attrs.add(new VariableEntry<Object>("bt", exc.getBacktrace()));
marshalStream.dumpVariables(attrs);
@@ -162,7 +162,7 @@ public Object unmarshalFrom(Ruby runtime, RubyClass type,
// just use real vars all the time for these?
unmarshalStream.defaultVariablesUnmarshal(exc);

exc.message = (IRubyObject)exc.removeInternalVariable("mesg");
exc.setMessage((IRubyObject)exc.removeInternalVariable("mesg"));
exc.errno = (IRubyObject)exc.removeInternalVariable("errno");
exc.set_backtrace((IRubyObject)exc.removeInternalVariable("bt"));

@@ -254,7 +254,7 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {
val += " - " + msg.convertToString();
}

message = runtime.newString(val);
setMessage(runtime.newString(val));
return this;
}

6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubySystemExit.java
Original file line number Diff line number Diff line change
@@ -73,15 +73,15 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {
final IRubyObject arg = args[0];
if (arg instanceof RubyFixnum) {
this.status = arg;
if (args.length > 1) this.message = args[1]; // (status, message)
if (args.length > 1) this.setMessage(args[1]); // (status, message)
}
else if (arg instanceof RubyBoolean) {
final Ruby runtime = getRuntime();
this.status = runtime.newFixnum( arg == runtime.getTrue() ? 0 : 1 );
if (args.length > 1) this.message = args[1]; // (status, message)
if (args.length > 1) this.setMessage(args[1]); // (status, message)
}
else {
this.message = arg;
this.setMessage(arg);
this.status = RubyFixnum.zero(getRuntime());
}
}
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyUncaughtThrowError.java
Original file line number Diff line number Diff line change
@@ -57,23 +57,23 @@ static RubyClass createUncaughtThrowErrorClass(Ruby runtime, RubyClass argumentE
protected RubyUncaughtThrowError(Ruby runtime, RubyClass exceptionClass) {
super(runtime, exceptionClass, exceptionClass.getName());
// this.tag = this.value = runtime.getNil();
this.message = runtime.getNil();
this.setMessage(runtime.getNil());
}

public static RubyUncaughtThrowError newUncaughtThrowError(final Ruby runtime,
IRubyObject tag, IRubyObject value, RubyString message) {
RubyUncaughtThrowError error = new RubyUncaughtThrowError(runtime, runtime.getUncaughtThrowError());
error.tag = tag;
error.value = value;
error.message = message;
error.setMessage(message);
return error;
}

@Override
@JRubyMethod(required = 2, optional = 1, visibility = Visibility.PRIVATE)
public IRubyObject initialize(IRubyObject[] args, Block block) {
this.tag = args[0]; this.value = args[1];
if ( args.length > 2 ) this.message = args[2];
if ( args.length > 2 ) this.setMessage(args[2]);
// makes no-sense for us to have a cause or does it ?!
// super.initialize(NULL_ARRAY, block); // already set message
return this;
@@ -87,12 +87,12 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {

@Override
public RubyString to_s(ThreadContext context) {
if ( message.isNil() ) {
if ( getMessage().isNil() ) {
return RubyString.newEmptyString(context.runtime);
}
if ( tag == null ) return message.asString();
if ( tag == null ) return getMessage().asString();

final RubyString str = message.asString();
final RubyString str = getMessage().asString();
return str.op_format(context, RubyArray.newArray(context.runtime, tag));
}

39 changes: 4 additions & 35 deletions core/src/test/java/org/jruby/javasupport/TestJava.java
Original file line number Diff line number Diff line change
@@ -122,50 +122,19 @@ public void testJavaConstructorExceptionHandling() throws Exception {
constructor.new_instance(new Object[] { -1 });
assert false;
}
catch (RaiseException ex) {
// ex.printStackTrace();
assertEquals("java.lang.IllegalStateException: param == -1", ex.getMessage());
catch (IllegalStateException ex) {
assertEquals("param == -1", ex.getMessage());
StackTraceElement e0 = ex.getStackTrace()[0];
assertEquals("org.jruby.test.ThrowingConstructor", e0.getClassName());
assertEquals("<init>", e0.getMethodName());

assertNotNull(ex.getCause());
assert ex.getCause() instanceof IllegalStateException;

assertNotNull(ex.getException());
assert ex.getException() instanceof NativeException;
assertEquals("java.lang.IllegalStateException: param == -1", ex.getException().message(runtime.getCurrentContext()).toString());
assertEquals("java.lang.IllegalStateException: param == -1", ex.getException().getMessage().toString());
assertEquals("param == -1", ex.getCause().getMessage());

assert ex.getException().backtrace() instanceof RubyArray;
RubyArray backtrace = (RubyArray) ex.getException().backtrace();
// org/jruby/test/ThrowingConstructor.java:8:in `<init>'
// java/lang/reflect/Constructor.java:423:in `newInstance'
// org/jruby/javasupport/JavaConstructor.java:222:in `new_instance'
// java/lang/reflect/Method.java:498:in `invoke'
// junit/framework/TestCase.java:176:in `runTest'
assert backtrace.get(0).toString().contains("org/jruby/test/ThrowingConstructor.java");
}

try {
constructor.new_instance(new Object[] { null }); // new IllegalStateException() null cause message
assert false;
}
catch (RaiseException ex) {
// ex.printStackTrace();
assertEquals("java.lang.IllegalStateException: null", ex.getMessage());

assertNotNull(ex.getCause());
assert ex.getCause() instanceof IllegalStateException;

assertNotNull(ex.getException());
assert ex.getException() instanceof NativeException;
assertEquals("java.lang.IllegalStateException: null", ex.getException().message(runtime.getCurrentContext()).toString());
assertEquals("java.lang.IllegalStateException: null", ex.getException().getMessage().toString());
assertNull(ex.getCause().getMessage());

assert ex.getException().backtrace() instanceof RubyArray;
catch (IllegalStateException ex) {
assertEquals(null, ex.getMessage());
}
}