@Override public void onFailure(Call call, IOException e) { synchronized (lock) { this.callFailure = (e instanceof UnexpectedException) ? e.getCause() : e; lock.notifyAll(); } }
private boolean isRecoverable(IOException e, boolean requestSendStarted) { // If there was a protocol problem, don't recover. if (e instanceof ProtocolException) { return false; } // If there was an interruption don't recover, but if there was a timeout connecting to a route // we should try the next route (if there is one). if (e instanceof InterruptedIOException) { return e instanceof SocketTimeoutException && !requestSendStarted; } // Look for known client-side or negotiation errors that are unlikely to be fixed by trying // again with a different route. if (e instanceof SSLHandshakeException) { // If the problem was a CertificateException from the X509TrustManager, // do not retry. if (e.getCause() instanceof CertificateException) { return false; } } if (e instanceof SSLPeerUnverifiedException) { // e.g. a certificate pinning error. return false; } // An example of one we might want to retry with a different route is a problem connecting to a // proxy and would manifest as a standard IOException. Unless it is one we know we should not // retry, we return true and try a new route. return true; }
if (e.getCause() instanceof CertificateException) { return false;
@Override public void onFailure(Call call, IOException e) { synchronized (lock) { this.callFailure = (e instanceof UnexpectedException) ? e.getCause() : e; lock.notifyAll(); } }
private static boolean isIOExceptionCausedByEPIPE(IOException e) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { return e.getMessage().contains("EPIPE"); } Throwable cause = e.getCause(); return cause instanceof ErrnoException && ((ErrnoException) cause).errno == OsConstants.EPIPE; }
@Override public Response toResponse(IOException e) { if (!(e.getCause() instanceof java.util.concurrent.TimeoutException)) { logger.warn("IOExceptionMapper", e); } return Response.status(503).build(); } }
@Override public void run() { List<String> cmdWrapper = new ArrayList<>(); cmdWrapper.add("nohup"); cmdWrapper.addAll(cmdlist); cmdWrapper.add("&"); try { launchProcess(cmdWrapper, environment); } catch (IOException e) { LOG.error("Failed to run nohup " + command + " &," + e.getCause(), e); } } }).start();
@Override public void run() { List<String> cmdWrapper = new ArrayList<String>(); cmdWrapper.add("nohup"); cmdWrapper.addAll(cmdlist); cmdWrapper.add("&"); try { launchProcess(cmdWrapper, environment); } catch (IOException e) { LOG.error("Failed to run nohup " + command + " &," + e.getCause(), e); } } }).start();
@Override public void shutDown() throws Exception { if (upNode != null) { try { upNode.close(); } catch (IOException e) { final Throwable cause = fromNullable(e.getCause()).or(e); log.warn("Exception on closing up node: {}", cause); } } }
@Override public void shutDown() throws Exception { if (upNode != null) { try { upNode.close(); } catch (IOException e) { final Throwable cause = fromNullable(e.getCause()).or(e); log.warn("Exception on closing up node: {}", cause); } } }
private boolean isEINPROGRESS(IOException e) { if (isBlocking()) { return false; } if (e instanceof ConnectException) { Throwable cause = e.getCause(); if (cause instanceof ErrnoException) { return ((ErrnoException) cause).errno == EINPROGRESS; } } return false; }
public void foo() { try (final InputStream foo = new ByteArrayInputStream(new byte[512])) { foo.read(); } catch (final IOException e) { e.getCause(); } } }
/** * Reverse operation of {@link #store(ConfidentialKey, byte[])} * * @return * null the data has not been previously persisted. */ @Override protected byte[] load(ConfidentialKey key) throws IOException { try { File f = getFileFor(key); if (!f.exists()) return null; Cipher sym = Secret.getCipher("AES"); sym.init(Cipher.DECRYPT_MODE, masterKey); try (InputStream fis=Files.newInputStream(f.toPath()); CipherInputStream cis = new CipherInputStream(fis, sym)) { byte[] bytes = IOUtils.toByteArray(cis); return verifyMagic(bytes); } } catch (GeneralSecurityException e) { throw new IOException("Failed to load the key: "+key.getId(),e); } catch (InvalidPathException e) { throw new IOException(e); } catch (IOException x) { if (x.getCause() instanceof BadPaddingException) { return null; // broken somehow } else { throw x; } } }
@SuppressWarnings("unchecked") protected <T> T _handleDateTimeException(DeserializationContext ctxt, Class<?> type, DateTimeException e0, String value) throws IOException { try { return (T) ctxt.handleWeirdKey(type, value, "Failed to deserialize %s: (%s) %s", type.getName(), e0.getClass().getName(), e0.getMessage()); } catch (JsonMappingException e) { e.initCause(e0); throw e; } catch (IOException e) { if (null == e.getCause()) { e.initCause(e0); } throw JsonMappingException.fromUnexpectedIOE(e); } } }
@SuppressWarnings("unchecked") protected <R> R _handleDateTimeException(DeserializationContext context, DateTimeException e0, String value) throws JsonMappingException { try { return (R) context.handleWeirdStringValue(handledType(), value, "Failed to deserialize %s: (%s) %s", handledType().getName(), e0.getClass().getName(), e0.getMessage()); } catch (JsonMappingException e) { e.initCause(e0); throw e; } catch (IOException e) { if (null == e.getCause()) { e.initCause(e0); } throw JsonMappingException.fromUnexpectedIOE(e); } }
private void handleEofException(IOException e) { if ((e instanceof EOFException || e.getCause() instanceof EOFException) && logQueue.size() > 1 && this.eofAutoRecovery) { try { if (fs.getFileStatus(logQueue.peek()).getLen() == 0) { LOG.warn("Forcing removal of 0 length log in queue: " + logQueue.peek()); logQueue.remove(); currentPosition = 0; } } catch (IOException ioe) { LOG.warn("Couldn't get file length information about log " + logQueue.peek()); } } }
/** * @throws Exception If failed. */ @Test public void testPutFieldsWithDefaultWriteObject() throws Exception { try { marshalUnmarshal(new CustomWriteObjectMethodObject("test")); } catch (IOException e) { assert e.getCause().getCause() instanceof NotActiveException; } }
@Test public void registerFailure() throws Exception { ChannelBuilder channelBuilder = new PlaintextChannelBuilder(null) { @Override public KafkaChannel buildChannel(String id, SelectionKey key, int maxReceiveSize, MemoryPool memoryPool) throws KafkaException { throw new RuntimeException("Test exception"); } @Override public void close() { } }; Selector selector = new Selector(5000, new Metrics(), new MockTime(), "MetricGroup", channelBuilder, new LogContext()); SocketChannel socketChannel = SocketChannel.open(); socketChannel.configureBlocking(false); try { selector.register("1", socketChannel); fail("Register did not fail"); } catch (IOException e) { assertTrue("Unexpected exception: " + e, e.getCause().getMessage().contains("Test exception")); assertFalse("Socket not closed", socketChannel.isOpen()); } selector.close(); }
@Test public void testWrapException() throws Exception { final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0); assertTrue(wrapException(address, new ConnectException()) instanceof ConnectException); assertTrue( wrapException(address, new SocketTimeoutException()) instanceof SocketTimeoutException); assertTrue(wrapException(address, new ConnectionClosingException( "Test AbstractRpcClient#wrapException")) instanceof ConnectionClosingException); assertTrue( wrapException(address, new CallTimeoutException("Test AbstractRpcClient#wrapException")) .getCause() instanceof CallTimeoutException); } }