Repository: netty/netty
File: transport-native-unix-common/src/main/java/io/netty/channel/unix/Errors.java (Java)

Code before:
        public int expectedErr() {
            return expectedErr;
        }

        @Override
        public synchronized Throwable fillInStackTrace() {
            if (fillInStackTrace) {
                return super.fillInStackTrace();
            }
            return this;
        }
    }

    public static final class NativeCallException extends RuntimeException {
        private static final long serialVersionUID = -5532328671712318161L;
        private final int expectedErr;
        private final boolean fillInStackTrace;

        public NativeCallException(String method, int expectedErr) {
            this(method, expectedErr, true);
        }

        public NativeCallException(String method, int expectedErr, boolean fillInStackTrace) {
            super(method + "(..) failed: " + errnoString(-expectedErr));
            this.expectedErr = expectedErr;
            this.fillInStackTrace = fillInStackTrace;
        }

        public int expectedErr() {
            return expectedErr;
        }

        @Override
        public Throwable fillInStackTrace() {
            if (fillInStackTrace) {
                return super.fillInStackTrace();
            }
            return this;
        }
    }

    static final class NativeConnectException extends ConnectException {
        private static final long serialVersionUID = -5532328671712318161L;
        private final int expectedErr;
        NativeConnectException(String method, int expectedErr) {
            super(method + "(..) failed: " + errnoString(-expectedErr));
            this.expectedErr = expectedErr;
        }

        int expectedErr() {
            return expectedErr;

Review comment (suggestion):
Instead of this business with the `fillInStackTrace` field, you can pass it to the `writableStackTrace` parameter of `RuntimeException`.

See the protected constructor here: https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html#RuntimeException-java.lang.String-java.lang.Throwable-boolean-boolean-

Code after:
        public int expectedErr() {
            return expectedErr;
        }

        @Override
        public synchronized Throwable fillInStackTrace() {
            if (fillInStackTrace) {
                return super.fillInStackTrace();
            }
            return this;
        }
    }

    static final class NativeConnectException extends ConnectException {
        private static final long serialVersionUID = -5532328671712318161L;
        private final int expectedErr;
        NativeConnectException(String method, int expectedErr) {
            super(method + "(..) failed: " + errnoString(-expectedErr));
            this.expectedErr = expectedErr;
        }

        int expectedErr() {
            return expectedErr;
        }
    }

    static {
        for (int i = 0; i < ERRORS.length; i++) {
            // This is ok as strerror returns 'Unknown error i' when the message is not known.
            ERRORS[i] = strError(i);
        }
    }

    public static boolean handleConnectErrno(String method, int err) throws IOException {
        if (err == ERRNO_EINPROGRESS_NEGATIVE || err == ERROR_EALREADY_NEGATIVE) {
            // connect not complete yet need to wait for EPOLLOUT event.
            // EALREADY has been observed when using tcp fast open on centos8.
            return false;
        }
        throw newConnectException0(method, err);
    }

    /**
     * @deprecated Use {@link #handleConnectErrno(String, int)}.
     * @param method The native method name which caused the errno.
     * @param err the negative value of the errno.
     * @throws IOException The errno translated into an exception.
     */
    @Deprecated
    public static void throwConnectException(String method, int err) throws IOException {
        if (err == ERROR_EALREADY_NEGATIVE) {