SerializedExceptionPBImpl extends SerializedException { @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()); } SerializedExceptionPBImpl();  SerializedExceptionPBImpl(SerializedExceptionProto proto); private  SerializedExceptionPBImpl(Throwable t); void init(String message); void init(Throwable t); void init(String message, Throwable t); @SuppressWarnings("unchecked") @Override Throwable deSerialize(); @Override String getMessage(); @Override String getRemoteTrace(); @Override SerializedException getCause(); SerializedExceptionProto getProto(); @Override int hashCode(); @Override boolean equals(Object other);  }
@Test public void testDeserialize() throws Exception { Exception ex = new Exception("test exception"); SerializedExceptionPBImpl pb = new SerializedExceptionPBImpl(); try { pb.deSerialize(); Assert.fail("deSerialze should throw YarnRuntimeException"); } catch (YarnRuntimeException e) { Assert.assertEquals(ClassNotFoundException.class, e.getCause().getClass()); } pb.init(ex); Assert.assertEquals(ex.toString(), pb.deSerialize().toString()); }