@SuppressWarnings("unchecked")
  @Override
  public Throwable deSerialize() {

    SerializedException cause = getCause();
    SerializedExceptionProtoOrBuilder p = viaProto ? proto : builder;
    Class<?> realClass = null;
    try {
      realClass = Class.forName(p.getClassName());
    } catch (ClassNotFoundException e) {
      throw new YarnRuntimeException(e);
    }
    Class classType = null;
    if (YarnException.class.isAssignableFrom(realClass)) {
      classType = YarnException.class;
    } else if (IOException.class.isAssignableFrom(realClass)) {
      classType = IOException.class;
    } else if (RuntimeException.class.isAssignableFrom(realClass)) {
      classType = RuntimeException.class;
    } else {
      classType = Throwable.class;
    }
    return instantiateException(realClass.asSubclass(classType), getMessage(),
      cause == null ? null : cause.deSerialize());
  }
@Test
  void testDeserialize() throws Exception {
    Exception ex = new Exception("test exception");
    SerializedExceptionPBImpl pb = new SerializedExceptionPBImpl();

    try {
      pb.deSerialize();
      fail("deSerialize should throw YarnRuntimeException");
    } catch (YarnRuntimeException e) {
      assertEquals(ClassNotFoundException.class,
          e.getCause().getClass());
    }

    pb.init(ex);
    assertEquals(ex.toString(), pb.deSerialize().toString());
  }