Exceptions { public static boolean isExpected(Throwable cause) { requireNonNull(cause, "cause"); if (Flags.verboseSocketExceptions()) { return false; } if (cause instanceof ClosedChannelException || cause instanceof ClosedSessionException) { return true; } final String msg = cause.getMessage(); if (msg != null) { if ((cause instanceof IOException || cause instanceof ChannelException) && IGNORABLE_SOCKET_ERROR_MESSAGE.matcher(msg).find()) { return true; } if (cause instanceof Http2Exception && IGNORABLE_HTTP2_ERROR_MESSAGE.matcher(msg).find()) { return true; } if (cause instanceof SSLException && IGNORABLE_TLS_ERROR_MESSAGE.matcher(msg).find()) { return true; } } return false; } private  Exceptions(); static void logIfUnexpected(Logger logger, Channel ch, Throwable cause); static void logIfUnexpected(Logger logger, Channel ch, String debugData, Throwable cause); static void logIfUnexpected(Logger logger, Channel ch,
                                       @Nullable SessionProtocol protocol, Throwable cause); static void logIfUnexpected(Logger logger, Channel ch, @Nullable SessionProtocol protocol,
                                       String debugData, Throwable cause); static boolean isExpected(Throwable cause); static boolean isStreamCancelling(Throwable cause); static T clearTrace(T exception); @SuppressWarnings("ReturnOfNull") static T throwUnsafely(Throwable cause); static void throwIfFatal(Throwable t); static Throwable peel(Throwable throwable); static String traceText(Throwable exception);  }
@Test public void testIsExpected() { final boolean expected = !Flags.verboseSocketExceptions(); assertThat(Exceptions.isExpected(new Exception())).isFalse(); assertThat(Exceptions.isExpected(new Exception("broken pipe"))).isFalse(); assertThat(Exceptions.isExpected(new Exception("connection reset by peer"))).isFalse(); assertThat(Exceptions.isExpected(new Exception("stream closed"))).isFalse(); assertThat(Exceptions.isExpected(new Exception("SSLEngine closed already"))).isFalse(); assertThat(Exceptions.isExpected(new ClosedChannelException())).isEqualTo(expected); assertThat(Exceptions.isExpected(ClosedSessionException.get())).isEqualTo(expected); assertThat(Exceptions.isExpected(new IOException("connection reset by peer"))).isEqualTo(expected); assertThat(Exceptions.isExpected(new IOException("invalid argument"))).isEqualTo(false); assertThat(Exceptions.isExpected(new ChannelException("broken pipe"))).isEqualTo(expected); assertThat(Exceptions.isExpected(new ChannelException("invalid argument"))).isEqualTo(false); assertThat(Exceptions.isExpected(new Http2Exception(Http2Error.INTERNAL_ERROR, "stream closed"))) .isEqualTo(expected); assertThat(Exceptions.isExpected(new Http2Exception(Http2Error.INTERNAL_ERROR))).isEqualTo(false); assertThat(Exceptions.isExpected(new SSLException("SSLEngine closed already"))).isEqualTo(expected); assertThat(Exceptions.isExpected(new SSLException("Handshake failed"))).isEqualTo(false); }