/** * Note: always throws the failure in some form. The return value is to keep the compiler happy. */ public static RuntimeException throwAsUncheckedException(Throwable t) { return throwAsUncheckedException(t, false); }
public boolean awaitNextResult() { try { if (next == null) { next = received.take(); } } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } return next != END; }
public void stop() { try { closeable.close(); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } } };
public void stop() { try { closeable.close(); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } } };
public URL transform(URI original) { try { return original.toURL(); } catch (MalformedURLException e) { throw UncheckedException.throwAsUncheckedException(e); } } };
public void describeCommand(Appendable output, String... args) { try { output.append(appName); for (String arg : args) { output.append(' '); output.append(arg); } } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } } }
public List<URL> getAsURLs() { List<URL> urls = new ArrayList<URL>(); for (File file : files) { try { urls.add(file.toURI().toURL()); } catch (MalformedURLException e) { throw UncheckedException.throwAsUncheckedException(e); } } return urls; }
private static <K, V> V uncheckedGet(LoadingCache<K, V> cache, K key) { try { return cache.get(key); } catch (ExecutionException e) { throw UncheckedException.throwAsUncheckedException(e.getCause()); } catch (UncheckedExecutionException e) { throw UncheckedException.throwAsUncheckedException(e.getCause()); } }
public void writeTo(File file) { try { OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); try { writeTo(outputStream); } finally { outputStream.close(); } } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } }
@Nullable protected MetaProperty lookupProperty(MetaClass metaClass, String name) { if (metaClass instanceof MetaClassImpl) { try { return (MetaProperty) META_PROP_METHOD.invoke(metaClass, name, false); } catch (Throwable e) { throw UncheckedException.throwAsUncheckedException(e); } } // Some other meta-class implementation - fall back to the public API return metaClass.getMetaProperty(name); }
private URI getDistribution(String repositoryUrl, GradleVersion version, String archiveName, String archiveClassifier) { try { return new URI(repositoryUrl + "/" + archiveName + "-" + version.getVersion() + "-" + archiveClassifier + ".zip"); } catch (URISyntaxException e) { throw UncheckedException.throwAsUncheckedException(e); } } }
public String readAsString(Charset charset) { try { return doReadAsString(charset); } catch (CharacterCodingException e) { throw UncheckedException.throwAsUncheckedException(e); } }
public F getValue(T target) { try { return returnType.cast(method.invoke(target)); } catch (InvocationTargetException e) { throw UncheckedException.unwrapAndRethrow(e); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } }
@Override public Object invoke(Object target, Object... args) { try { return javaMethod.invoke(target, args); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } }
public void dispatch(MethodInvocation message) { try { Method method = message.getMethod(); method.setAccessible(true); method.invoke(target, message.getArguments()); } catch (InvocationTargetException e) { throw UncheckedException.throwAsUncheckedException(e.getCause()); } catch (Throwable throwable) { throw UncheckedException.throwAsUncheckedException(throwable); } } }
@Override public FileWatcher watch(Action<? super Throwable> onError, FileWatcherListener listener) { try { WatchService watchService = FileSystems.getDefault().newWatchService(); WatchServiceFileWatcherBacking backing = new WatchServiceFileWatcherBacking(onError, listener, watchService, fileSystem); return backing.start(executor); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } } }
@Override public void put(K key, V value) { ByteArrayOutputStream outstr = new ByteArrayOutputStream(); OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(outstr); try { valueSerializer.write(encoder, value); encoder.flush(); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } entries.put(key, outstr.toByteArray()); }
@Override public Object invoke(Object target, Object... args) { try { return method.bindTo(target).invokeWithArguments(args); } catch (Throwable e) { throw UncheckedException.throwAsUncheckedException(e); } } }
public Node asNode() { if (node == null) { try { node = new XmlParser().parseText(toString()); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } builder = null; element = null; } return node; }
@Override public <T> T withLocks(Iterable<? extends ResourceLock> locks, Callable<T> action) { coordinationService.withStateLock(lock(locks)); try { return action.call(); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } finally { coordinationService.withStateLock(unlock(locks)); } }