Skip to content

Commit

Permalink
Showing 65 changed files with 2,190 additions and 1,807 deletions.
25 changes: 11 additions & 14 deletions core/src/main/java/org/jruby/Main.java
Original file line number Diff line number Diff line change
@@ -316,36 +316,34 @@ public void run() {
}
}

private Status handleUnsupportedClassVersion(UnsupportedClassVersionError ucve) {
private Status handleUnsupportedClassVersion(UnsupportedClassVersionError ex) {
config.getError().println("Error: Some library (perhaps JRuby) was built with a later JVM version.");
config.getError().println("Please use libraries built with the version you intend to use or an earlier one.");
if (config.isVerbose()) {
config.getError().println("Exception trace follows:");
ucve.printStackTrace();
ex.printStackTrace(config.getError());
} else {
config.getError().println("Specify -w for full UnsupportedClassVersionError stack trace");
config.getError().println("Specify -w for full " + ex + " stack trace");
}
return new Status(1);
}

/**
* Print a nicer stack size error since Rubyists aren't used to seeing this.
*/
private Status handleStackOverflow(StackOverflowError soe) {
private Status handleStackOverflow(StackOverflowError ex) {
String memoryMax = getRuntimeFlagValue("-Xss");

if (memoryMax != null) {
config.getError().println("Error: Your application used more stack memory than the safety cap of " + memoryMax + ".");
config.getError().println("Error: Your application used more stack memory than the safety cap of " + memoryMax + '.');
} else {
config.getError().println("Error: Your application used more stack memory than the default safety cap.");
}
config.getError().println("Specify -J-Xss####k to increase it (#### = cap size in KB).");

if (config.isVerbose()) {
config.getError().println("Exception trace follows:");
soe.printStackTrace(config.getError());
ex.printStackTrace(config.getError());
} else {
config.getError().println("Specify -w for full StackOverflowError stack trace");
config.getError().println("Specify -w for full " + ex + " stack trace");
}

return new Status(1);
@@ -354,10 +352,10 @@ private Status handleStackOverflow(StackOverflowError soe) {
/**
* Print a nicer memory error since Rubyists aren't used to seeing this.
*/
private Status handleOutOfMemory(OutOfMemoryError oome) {
private Status handleOutOfMemory(OutOfMemoryError ex) {
System.gc(); // try to clean up a bit of space, hopefully, so we can report this error

String oomeMessage = oome.getMessage();
String oomeMessage = ex.getMessage();
boolean heapError = false;

if (oomeMessage != null) {
@@ -387,10 +385,9 @@ private Status handleOutOfMemory(OutOfMemoryError oome) {
}

if (config.isVerbose()) {
config.getError().println("Exception trace follows:");
oome.printStackTrace(config.getError());
ex.printStackTrace(config.getError());
} else {
config.getError().println("Specify -w for full OutOfMemoryError stack trace");
config.getError().println("Specify -w for full " + ex + " stack trace");
}

return new Status(1);
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -825,6 +825,10 @@ public IRubyObject checkArrayType() {
*/
@Override
public Object toJava(Class target) {
return defaultToJava(target);
}

final <T> T defaultToJava(Class<T> target) {
// for callers that unconditionally pass null retval type (JRUBY-4737)
if (target == void.class) return null;

@@ -838,7 +842,7 @@ public Object toJava(Class target) {
if (target.isAssignableFrom(value.getClass())) {
getRuntime().getJavaSupport().getObjectProxyCache().put(value, this);

return value;
return (T) value;
}
}
else if (JavaUtil.isDuckTypeConvertable(getClass(), target)) {
@@ -847,7 +851,7 @@ else if (JavaUtil.isDuckTypeConvertable(getClass(), target)) {
}
}
else if (target.isAssignableFrom(getClass())) {
return this;
return (T) this;
}

throw getRuntime().newTypeError("cannot convert instance of " + getClass() + " to " + target);
Loading

0 comments on commit bb97a8f

Please sign in to comment.