@Test
  public void testRemoteFromLocal() throws IOException {
    String errorMsg = "some message";
    Exception generic = new Exception(errorMsg);
    generic.printStackTrace();
    assertTrue(generic.getMessage().contains(errorMsg));

    ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, generic));

    // Workaround for java 11 - replaced assertArrayEquals with individual elements comparison
    // using custom comparison helper method
    assertEquals("Stacktrace lengths don't match", generic.getStackTrace().length,
      e.getCause().getStackTrace().length);
    for (int i = 0; i < generic.getStackTrace().length; i++) {
      assertTrue("Local stack trace got corrupted at " + i + "th index",
        compareStackTraceElement(generic.getStackTrace()[i], e.getCause().getStackTrace()[i]));
    }

    e.printStackTrace(); // should have ForeignException and source node in it.
    assertTrue(e.getCause().getCause() == null);

    // verify that original error message is present in Foreign exception message
    assertTrue(e.getCause().getMessage().contains(errorMsg));
  }
Compare that a generic exception's stack trace has the same stack trace elements after
serialization and deserialization
hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java