Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8236285: [JVMCI] improve TranslatedException traces
Reviewed-by: never, kvn
  • Loading branch information
Doug Simon committed Mar 18, 2020
1 parent bf54c47 commit 34b9ac22871861053ef61135af31da15eaf94195
@@ -36,8 +36,14 @@
@SuppressWarnings("serial")
final class TranslatedException extends Exception {

private TranslatedException(String message, Throwable translationFailure) {
super("[" + translationFailure + "]" + Objects.toString(message, ""));
/**
* Class name of exception that could not be instantiated.
*/
private String originalExceptionClassName;

private TranslatedException(String message, String originalExceptionClassName) {
super(message);
this.originalExceptionClassName = originalExceptionClassName;
}

/**
@@ -49,6 +55,18 @@ public Throwable fillInStackTrace() {
return this;
}

@Override
public String toString() {
String s;
if (originalExceptionClassName.equals(TranslatedException.class.getName())) {
s = getClass().getName();
} else {
s = getClass().getName() + "[" + originalExceptionClassName + "]";
}
String message = getMessage();
return (message != null) ? (s + ": " + message) : s;
}

/**
* Prints a stack trace for {@code throwable} and returns {@code true}. Used to print stack
* traces only when assertions are enabled.
@@ -86,14 +104,9 @@ private static Throwable create(String className, String message, Throwable caus
if (message == null) {
return initCause((Throwable) cls.getConstructor().newInstance(), cause);
}
cls.getDeclaredConstructor(String.class);
return initCause((Throwable) cls.getConstructor(String.class).newInstance(message), cause);
return initCause((Throwable) cls.getDeclaredConstructor(String.class).newInstance(message), cause);
} catch (Throwable translationFailure) {
if (className.equals(TranslatedException.class.getName())) {
// Chop the class name when boxing another TranslatedException
return initCause(new TranslatedException(message, translationFailure), cause);
}
return initCause(new TranslatedException(null, translationFailure), cause);
return initCause(new TranslatedException(message, className), cause);
}
}

@@ -236,7 +249,7 @@ static Throwable decodeThrowable(String encodedThrowable) {
return throwable;
} catch (Throwable translationFailure) {
assert printStackTrace(translationFailure);
return new TranslatedException("Error decoding exception: " + encodedThrowable, translationFailure);
return new TranslatedException("Error decoding exception: " + encodedThrowable, translationFailure.getClass().getName());
}
}
}
@@ -75,7 +75,7 @@ private static void assertThrowableEquals(Throwable original, Throwable decoded)
while (original != null) {
if (Untranslatable.class.equals(original.getClass())) {
Assert.assertEquals("jdk.vm.ci.hotspot.TranslatedException", decoded.getClass().getName());
Assert.assertEquals("[java.lang.ClassNotFoundException: jdk/vm/ci/hotspot/test/TestTranslatedException$Untranslatable]", decoded.getMessage());
Assert.assertEquals("jdk.vm.ci.hotspot.TranslatedException[jdk.vm.ci.hotspot.test.TestTranslatedException$Untranslatable]: test exception", decoded.toString());
Assert.assertEquals("test exception", original.getMessage());
} else {
Assert.assertEquals(original.getClass().getName(), decoded.getClass().getName());

0 comments on commit 34b9ac2

Please sign in to comment.