Skip to content

Commit

Permalink
Re-encapsulate message RubyException.message field. See #4196.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Dec 13, 2016
1 parent 36fb12d commit 7dbb838
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 32 deletions.
9 changes: 2 additions & 7 deletions core/src/main/java/org/jruby/NativeException.java
Expand Up @@ -167,18 +167,13 @@ public void trimStackTrace(Member target) {
}

@Override
@SuppressWarnings("deprecation")
public final IRubyObject getMessage() {
if (message == null) {
if (messageAsJavaString == null) {
message = getRuntime().getNil();
} else {
message = getRuntime().newString(messageAsJavaString);
return message = getRuntime().getNil();
}

return message;
return message = getRuntime().newString(messageAsJavaString);
}

return message;
}

Expand Down
12 changes: 5 additions & 7 deletions core/src/main/java/org/jruby/RubyException.java
Expand Up @@ -134,7 +134,6 @@ public RubyException exception(IRubyObject[] args) {
}

@JRubyMethod(name = "to_s")
@SuppressWarnings("deprecation")
public IRubyObject to_s(ThreadContext context) {
final IRubyObject msg = getMessage();
if ( ! msg.isNil() ) return msg.asString();
Expand Down Expand Up @@ -273,7 +272,7 @@ public void initBacktrace() {
}

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

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

public static final int TRACE_HEAD = 8;
public static final int TRACE_TAIL = 4;
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyNameError.java
Expand Up @@ -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.setMessage(args[0]);
if (getMessage() instanceof RubyNameErrorMessage) this.receiver = ((RubyNameErrorMessage) getMessage()).object;
if ( args.length > 0 ) this.message = args[0];
if (message instanceof RubyNameErrorMessage) this.receiver = ((RubyNameErrorMessage) message).object;
if ( args.length > 1 ) this.name = args[1];
else this.name = getRuntime().getNil();
super.initialize(NULL_ARRAY, block); // message already set
Expand All @@ -229,12 +229,12 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {
@JRubyMethod
@Override
public IRubyObject to_s(ThreadContext context) {
if (getMessage().isNil()) {
if (message.isNil()) {
return context.runtime.newString(getMetaClass().getRealClass().getName());
}
RubyString str = getMessage().convertToString();
if (str != getMessage()) setMessage(str);
return getMessage();
RubyString str = message.convertToString();
if (str != message) message = str;
return message;
}

@JRubyMethod
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubySystemCallError.java
Expand Up @@ -139,7 +139,6 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {

private static final ObjectMarshal SYSTEM_CALL_ERROR_MARSHAL = new ObjectMarshal() {
@Override
@SuppressWarnings("deprecation")
public void marshalTo(Ruby runtime, Object obj, RubyClass type,
MarshalStream marshalStream) throws IOException {
RubySystemCallError exc = (RubySystemCallError) obj;
Expand All @@ -163,7 +162,7 @@ public Object unmarshalFrom(Ruby runtime, RubyClass type,
// just use real vars all the time for these?
unmarshalStream.defaultVariablesUnmarshal(exc);

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubySystemExit.java
Expand Up @@ -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.setMessage(args[1]); // (status, message)
if (args.length > 1) this.message = 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.setMessage(args[1]); // (status, message)
if (args.length > 1) this.message = args[1]; // (status, message)
}
else {
this.setMessage(arg);
this.message = arg;
this.status = RubyFixnum.zero(getRuntime());
}
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyUncaughtThrowError.java
Expand Up @@ -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.setMessage(runtime.getNil());
this.message = 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.setMessage(message);
error.message = 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.setMessage(args[2]);
if ( args.length > 2 ) this.message = args[2];
// makes no-sense for us to have a cause or does it ?!
// super.initialize(NULL_ARRAY, block); // already set message
return this;
Expand All @@ -87,12 +87,12 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {

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

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

Expand Down

0 comments on commit 7dbb838

Please sign in to comment.