@SuppressWarnings("unchecked")
    public static <T> T deserializeObject(InputStream in, ClassLoader cl, boolean isFailureTolerant)
            throws IOException, ClassNotFoundException {

        final ClassLoader old = Thread.currentThread().getContextClassLoader();
        // not using resource try to avoid AutoClosable's close() on the given stream
        try {
            ObjectInputStream oois = isFailureTolerant
                    ? new InstantiationUtil.FailureTolerantObjectInputStream(in, cl)
                    : new InstantiationUtil.ClassLoaderObjectInputStream(in, cl);
            Thread.currentThread().setContextClassLoader(cl);
            return (T) oois.readObject();
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }
    }
Utility class to create instances from class objects and checking failure reasons.

<p>Copied from Flink project.</p>
inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/util/InstantiationUtil.java