<commit_before>package net.openhft.chronicle.network.internal;

import java.io.IOException;
import java.net.SocketException;

public final class SocketExceptionUtil {

    private SocketExceptionUtil() {
    }

    /**
     * Is the passed exception one that results from reading from or writing to a reset
     * connection?
     * <p>
     * NOTE: This is not reliable and shouldn't be used for anything critical. We use it
     * to make logging less noisy, false negatives are acceptable and expected. It should
     * not produce false positives, but there's no guarantees it doesn't.
     *
     * @param e The exception
     * @return true if the exception is one that signifies the connection was reset
     */
    public static boolean isAConnectionResetException(IOException e) {
        return isALinuxJava12OrLessConnectionResetException(e)
                || isAWindowsConnectionResetException(e)
                || isALinuxJava13OrGreaterConnectionResetException(e);
    }

    private static boolean isALinuxJava13OrGreaterConnectionResetException(IOException e) {
        return e.getClass().equals(SocketException.class) && "Connection reset".equals(e.getMessage());
    }

    private static boolean isAWindowsConnectionResetException(IOException e) {
        return e.getClass().equals(IOException.class) && "An existing connection was forcibly closed by the remote host".equals(e.getMessage());
    }

    private static boolean isALinuxJava12OrLessConnectionResetException(IOException e) {
        return e.getClass().equals(IOException.class) && "Connection reset by peer".equals(e.getMessage());
    }<commit_msg>Add warning when transient exception suppression is unavailable due to locale<commit_after>package net.openhft.chronicle.network.internal;

import net.openhft.chronicle.core.Jvm;

import java.io.IOException;
import java.net.SocketException;
import java.util.Locale;

public final class SocketExceptionUtil {

    private SocketExceptionUtil() {
    }

    /**
     * Is the passed exception one that results from reading from or writing to a reset
     * connection?
     * <p>
     * NOTE: This is not reliable and shouldn't be used for anything critical. We use it
     * to make logging less noisy, false negatives are acceptable and expected. It should
     * not produce false positives, but there's no guarantees it doesn't.
     *
     * @param e The exception
     * @return true if the exception is one that signifies the connection was reset
     */
    public static boolean isAConnectionResetException(IOException e) {
        Language.warnOnce();

        return isALinuxJava12OrLessConnectionResetException(e)
                || isAWindowsConnectionResetException(e)
                || isALinuxJava13OrGreaterConnectionResetException(e);
    }

    private static boolean isALinuxJava13OrGreaterConnectionResetException(IOException e) {
        return e.getClass().equals(SocketException.class) && "Connection reset".equals(e.getMessage());
    }

    private static boolean isAWindowsConnectionResetException(IOException e) {
        return e.getClass().equals(IOException.class) && "An existing connection was forcibly closed by the remote host".equals(e.getMessage());
    }

    private static boolean isALinuxJava12OrLessConnectionResetException(IOException e) {
        return e.getClass().equals(IOException.class) && "Connection reset by peer".equals(e.getMessage());
    }

    private static final class Language {
        static {
            if (!Locale.getDefault().getLanguage().equals(Locale.ENGLISH.getLanguage())) {
                Jvm.warn().on(SocketExceptionUtil.class,
                        "Running under non-English locale '" + Locale.getDefault().getLanguage() +
                                "', transient exceptions will be reported with higher level than necessary.");
            }
        }

        static void warnOnce() {
            // No-op.
        }
    }
{'fraction_non_alphanumeric': 0.08212927756653993, 'fraction_numerical': 0.004055766793409379, 'mean_word_length': 3.20682302771855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3231192', 'n_tokens_mistral': 1002, 'n_tokens_neox': 955, 'n_words': 303}