Fix Throwable.toString

This commit is contained in:
Alexey Andreev 2019-02-13 19:19:15 +03:00
parent acc48f4532
commit 463f24506d
2 changed files with 19 additions and 5 deletions

View File

@ -134,8 +134,11 @@ public class TThrowable extends RuntimeException {
@Remove
public native Class<?> getClass0();
@Remove
public native String toString0();
@Rename("toString")
public String toString0() {
String message = getLocalizedMessage();
return getClass().getName() + (message != null ? ": " + message : "");
}
public TThrowable initCause(TThrowable cause) {
if (this.cause != this && this.cause != null) {
@ -155,9 +158,9 @@ public class TThrowable extends RuntimeException {
public void printStackTrace(PrintStream stream) {
stream.print(getClass().getName());
String message = getMessage();
String message = getLocalizedMessage();
if (message != null) {
stream.print(": " + getMessage());
stream.print(": " + message);
}
stream.println();
if (stackTrace != null) {
@ -173,7 +176,12 @@ public class TThrowable extends RuntimeException {
}
public void printStackTrace(PrintWriter stream) {
stream.println(getClass().getName() + ": " + getMessage());
stream.print(getClass().getName());
String message = getLocalizedMessage();
if (message != null) {
stream.print(": " + message);
}
stream.println();
if (stackTrace != null) {
for (TStackTraceElement element : stackTrace) {
stream.print(" at ");

View File

@ -29,4 +29,10 @@ public class ThrowableTest {
assertTrue(e.getCause() instanceof RuntimeException);
assertEquals("OK", e.getCause().getMessage());
}
@Test
public void toStringWorks() {
assertEquals("java.lang.RuntimeException: fail", new RuntimeException("fail").toString());
assertEquals("java.lang.RuntimeException", new RuntimeException().toString());
}
}