public static byte[] serializeOrDiscard(StateObject stateObject) throws Exception {
        try {
            return InstantiationUtil.serializeObject(stateObject);
        } catch (Exception e) {
            try {
                stateObject.discardState();
            } catch (Exception discardException) {
                e.addSuppressed(discardException);
            }

            ExceptionUtils.rethrowException(e);
        }

        // will never happen but is added to please the compiler
        return new byte[0];
    }
@Test
    void testSerializationOrDiscardWithDiscardFailure() throws Exception {
        final Exception discardException =
                new IllegalStateException(
                        "Expected IllegalStateException that should be suppressed.");
        final StateObject original =
                new FailingSerializationStateObject(
                        () -> {
                            throw discardException;
                        });

        assertThatThrownBy(() -> StateHandleStoreUtils.serializeOrDiscard(original))
                .withFailMessage("An IOException is expected to be thrown.")
                .isInstanceOf(IOException.class)
                .satisfies(
                        e -> {
                            assertThat(e.getSuppressed()).hasSize(1);
                            assertThat(e.getSuppressed()[0]).isEqualTo(discardException);
                        });
    }