/** * Rethrows the argument as {@code IOException} or {@code RuntimeException} * if it's not null. * * @deprecated This method is deprecated in favor of {@link #rethrowAlways}. Code should * be updated to {@link #rethrowAlways} and guarded with an additional null-argument check * (because {@link #rethrowAlways} is not accepting null arguments). */ @Deprecated public static void reThrow(Throwable th) throws IOException { if (th != null) { throw rethrowAlways(th); } }
private Partition getPartition(Future<Partition> future) throws IOException { try { return future.get(); } catch (InterruptedException ie) { throw new ThreadInterruptedException(ie); } catch (ExecutionException ee) { // Theoretically cause can be null; guard against that. Throwable cause = ee.getCause(); throw IOUtils.rethrowAlways(cause != null ? cause : ee); } }
/** * Closes all given <tt>Closeable</tt>s. * @see #close(Closeable...) */ public static void close(Iterable<? extends Closeable> objects) throws IOException { Throwable th = null; for (Closeable object : objects) { try { if (object != null) { object.close(); } } catch (Throwable t) { th = useOrSuppress(th, t); } } if (th != null) { throw rethrowAlways(th); } }
/** * Deletes all given <tt>Path</tt>s, if they exist. Some of the * <tt>File</tt>s may be null; they are * ignored. After everything is deleted, the method either * throws the first exception it hit while deleting, or * completes normally if there were no exceptions. * * @param files files to delete */ public static void deleteFilesIfExist(Collection<? extends Path> files) throws IOException { Throwable th = null; for (Path file : files) { try { if (file != null) { Files.deleteIfExists(file); } } catch (Throwable t) { th = useOrSuppress(th, t); } } if (th != null) { throw rethrowAlways(th); } }
/** Remove all our references to readers, and commits * any pending changes. */ synchronized void dropAll() throws IOException { Throwable priorE = null; final Iterator<Map.Entry<SegmentCommitInfo,ReadersAndUpdates>> it = readerMap.entrySet().iterator(); while(it.hasNext()) { final ReadersAndUpdates rld = it.next().getValue(); // Important to remove as-we-go, not with .clear() // in the end, in case we hit an exception; // otherwise we could over-decref if close() is // called again: it.remove(); // NOTE: it is allowed that these decRefs do not // actually close the SRs; this happens when a // near real-time reader is kept open after the // IndexWriter instance is closed: try { rld.dropReaders(); } catch (Throwable t) { priorE = IOUtils.useOrSuppress(priorE, t); } } assert readerMap.size() == 0; if (priorE != null) { throw IOUtils.rethrowAlways(priorE); } }
/** Called on exception, to check whether the checksum is also corrupt in this source, and add that * information (checksum matched or didn't) as a suppressed exception. */ private Error verifyChecksum(Throwable priorException, PointWriter writer) throws IOException { assert priorException != null; // TODO: we could improve this, to always validate checksum as we recurse, if we shared left and // right reader after recursing to children, and possibly within recursed children, // since all together they make a single pass through the file. But this is a sizable re-org, // and would mean leaving readers (IndexInputs) open for longer: if (writer instanceof OfflinePointWriter) { // We are reading from a temp file; go verify the checksum: String tempFileName = ((OfflinePointWriter) writer).name; try (ChecksumIndexInput in = tempDir.openChecksumInput(tempFileName, IOContext.READONCE)) { CodecUtil.checkFooter(in, priorException); } } // We are reading from heap; nothing to add: throw IOUtils.rethrowAlways(priorException); }
private static void checkSoftDeletes(String softDeletesField, SegmentCommitInfo info, SegmentReader reader, PrintStream infoStream, boolean failFast) throws IOException { if (infoStream != null) infoStream.print(" test: check soft deletes....."); try { int softDeletes = PendingSoftDeletes.countSoftDeletes(DocValuesFieldExistsQuery.getDocValuesDocIdSetIterator(softDeletesField, reader), reader.getLiveDocs()); if (softDeletes != info.getSoftDelCount()) { throw new RuntimeException("actual soft deletes: " + softDeletes + " but expected: " +info.getSoftDelCount()); } } catch (Exception e) { if (failFast) { throw IOUtils.rethrowAlways(e); } msg(infoStream, "ERROR [" + String.valueOf(e.getMessage()) + "]"); if (infoStream != null) { e.printStackTrace(infoStream); } } }
/** * Deletes all given file names. Some of the * file names may be null; they are * ignored. After everything is deleted, the method either * throws the first exception it hit while deleting, or * completes normally if there were no exceptions. * * @param dir Directory to delete files from * @param names file names to delete */ public static void deleteFiles(Directory dir, Collection<String> names) throws IOException { Throwable th = null; for (String name : names) { if (name != null) { try { dir.deleteFile(name); } catch (Throwable t) { th = useOrSuppress(th, t); } } } if (th != null) { throw rethrowAlways(th); } }
throw IOUtils.rethrowAlways(firstThrowable);
} catch (Throwable e) { if (failFast) { throw IOUtils.rethrowAlways(e);
/** Decrefs all provided files, even on exception; throws first exception hit, if any. */ void decRef(Collection<String> files) throws IOException { assert locked(); Set<String> toDelete = new HashSet<>(); Throwable firstThrowable = null; for(final String file : files) { try { if (decRef(file)) { toDelete.add(file); } } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t); } } try { deleteFiles(toDelete); } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t); } if (firstThrowable != null) { throw IOUtils.rethrowAlways(firstThrowable); } }
} catch (Throwable e) { if (failFast) { throw IOUtils.rethrowAlways(e);
} catch (Throwable e) { if (failFast) { throw IOUtils.rethrowAlways(e);
throw IOUtils.rethrowAlways(e);
} catch (Throwable e) { if (failFast) { throw IOUtils.rethrowAlways(e);
} catch (Throwable e) { if (failFast) { throw IOUtils.rethrowAlways(e);
throw IOUtils.rethrowAlways(priorException);
final private void handleMergeException(Throwable t, MergePolicy.OneMerge merge) throws IOException { if (infoStream.isEnabled("IW")) { infoStream.message("IW", "handleMergeException: merge=" + segString(merge.segments) + " exc=" + t); } // Set the exception on the merge, so if // forceMerge is waiting on us it sees the root // cause exception: merge.setException(t); addMergeException(merge); if (t instanceof MergePolicy.MergeAbortedException) { // We can ignore this exception (it happens when // deleteAll or rollback is called), unless the // merge involves segments from external directories, // in which case we must throw it so, for example, the // rollbackTransaction code in addIndexes* is // executed. if (merge.isExternal) { // TODO can we simplify this and just throw all the time? this would simplify this a lot throw (MergePolicy.MergeAbortedException) t; } } else { assert t != null; throw IOUtils.rethrowAlways(t); } }
/** * Test the term index. * @lucene.experimental */ public static Status.TermIndexStatus testPostings(CodecReader reader, PrintStream infoStream, boolean verbose, boolean failFast, Version version) throws IOException { // TODO: we should go and verify term vectors match, if // crossCheckTermVectors is on... Status.TermIndexStatus status; final int maxDoc = reader.maxDoc(); try { if (infoStream != null) { infoStream.print(" test: terms, freq, prox..."); } final Fields fields = reader.getPostingsReader().getMergeInstance(); final FieldInfos fieldInfos = reader.getFieldInfos(); status = checkFields(fields, reader.getLiveDocs(), maxDoc, fieldInfos, true, false, infoStream, verbose, version); } catch (Throwable e) { if (failFast) { throw IOUtils.rethrowAlways(e); } msg(infoStream, "ERROR: " + e); status = new Status.TermIndexStatus(); status.error = e; if (infoStream != null) { e.printStackTrace(infoStream); } } return status; }
throw IOUtils.rethrowAlways(e);