Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* that arose during translation.
*/
@SuppressWarnings("serial")
final class TranslatedException extends Exception {
public final class TranslatedException extends Exception {

/**
* The value returned by {@link #encodeThrowable(Throwable)} when encoding
Expand Down
24 changes: 18 additions & 6 deletions test/jdk/jdk/internal/vm/TestTranslatedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.testng.annotations.Test;

import jdk.internal.misc.Unsafe;
import jdk.internal.vm.TranslatedException;
import jdk.internal.vm.VMSupport;

public class TestTranslatedException {
Expand Down Expand Up @@ -100,6 +101,15 @@ public void encodeDecodeTest() throws Exception {
try {
VMSupport.decodeAndThrowThrowable(4, 0L, true, false);
throw new AssertionError("expected decodeAndThrowThrowable to throw an exception");
} catch (TranslatedException decoded) {
Assert.assertEquals(decoded.getCause().getClass(), OutOfMemoryError.class);
} catch (Throwable decoded) {
throw new AssertionError("unexpected exception: " + decoded);
}

try {
VMSupport.decodeAndThrowThrowable(5, 0L, true, false);
throw new AssertionError("expected decodeAndThrowThrowable to throw an exception");
} catch (InternalError decoded) {
// Expected
} catch (Throwable decoded) {
Expand Down Expand Up @@ -142,7 +152,7 @@ private void encodeDecode(Throwable throwable) throws Exception {
VMSupport.decodeAndThrowThrowable(format, buffer, true, false);
throw new AssertionError("expected decodeAndThrowThrowable to throw an exception");
} catch (Throwable decoded) {
assertThrowableEquals(throwable, decoded);
assertThrowableEquals(throwable, decoded.getCause());
}
return;
}
Expand All @@ -152,13 +162,15 @@ private void encodeDecode(Throwable throwable) throws Exception {
}
}

private static void assertThrowableEquals(Throwable original, Throwable decoded) {
private static void assertThrowableEquals(Throwable originalIn, Throwable decodedIn) {
Throwable original = originalIn;
Throwable decoded = decodedIn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this renaming?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the printing down the bottom of this message shows the complete throwable, not just the cause on which the comparison failed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I missed the reassign in the folded unchanged code.

try {
Assert.assertEquals(original == null, decoded == null);
while (original != null) {
if (Untranslatable.class.equals(original.getClass())) {
Assert.assertEquals(decoded.getClass().getName(), "jdk.internal.vm.TranslatedException");
Assert.assertEquals(decoded.toString(), "jdk.internal.vm.TranslatedException[jdk.internal.vm.test.TestTranslatedException$Untranslatable]: test exception");
Assert.assertEquals(decoded.getClass().getName(), "java.lang.InternalError");
Assert.assertEquals(decoded.toString(), "java.lang.InternalError: test exception [jdk.internal.vm.test.TestTranslatedException$Untranslatable]");
Assert.assertEquals(original.getMessage(), "test exception");
} else {
Assert.assertEquals(decoded.getClass().getName(), original.getClass().getName());
Expand All @@ -182,10 +194,10 @@ private static void assertThrowableEquals(Throwable original, Throwable decoded)
}
} catch (AssertionError e) {
System.err.println("original:[");
original.printStackTrace(System.err);
originalIn.printStackTrace(System.err);
System.err.println("]");
System.err.println("decoded:[");
original.printStackTrace(System.err);
decodedIn.printStackTrace(System.err);
System.err.println("]");
throw e;
}
Expand Down