IncompleteDeserializationException extends RuntimeException { @NotNull public DiscoveryCustomMessage message() { return m; } IncompleteDeserializationException(@NotNull DiscoveryCustomMessage m); @NotNull DiscoveryCustomMessage message();  }
@Test public void testMissingClassDeserialization() throws Exception { try (ObjectInputStream in = new ObjectInputStream(getClass().getResourceAsStream("Wrapper.ser"))) { in.readObject(); fail("Exception is expected"); } catch (IncompleteDeserializationException e) { Wrapper wrp = (Wrapper)e.message(); assertNotNull(wrp); assertEquals(42, wrp.i); assertNull(wrp.o); } }