mirror of https://github.com/apache/lucene.git
Simplify for Java 7, which has support for new IOException(message, cause)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1595223 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
52d1ab7919
commit
67b7b43b49
|
@ -56,17 +56,14 @@ public class StreamUtils {
|
|||
try {
|
||||
return csfType==null ? in : new CompressorStreamFactory().createCompressorInputStream(csfType, in);
|
||||
} catch (CompressorException e) {
|
||||
IOException ioe = new IOException(e.getMessage());
|
||||
ioe.initCause(e);
|
||||
throw ioe; }
|
||||
throw new IOException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
private OutputStream outputStream(OutputStream os) throws IOException {
|
||||
try {
|
||||
return csfType==null ? os : new CompressorStreamFactory().createCompressorOutputStream(csfType, os);
|
||||
} catch (CompressorException e) {
|
||||
IOException ioe = new IOException(e.getMessage());
|
||||
ioe.initCause(e);
|
||||
throw ioe;
|
||||
throw new IOException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,9 +168,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
|
|||
try {
|
||||
bd = (BigDecimal) decoder.parse(scratch.utf8ToString());
|
||||
} catch (ParseException pe) {
|
||||
CorruptIndexException e = new CorruptIndexException("failed to parse BigDecimal value (resource=" + in + ")");
|
||||
e.initCause(pe);
|
||||
throw e;
|
||||
throw new CorruptIndexException("failed to parse BigDecimal value (resource=" + in + ")", pe);
|
||||
}
|
||||
SimpleTextUtil.readLine(in, scratch); // read the line telling us if its real or not
|
||||
return BigInteger.valueOf(field.minValue).add(bd.toBigIntegerExact()).longValue();
|
||||
|
@ -231,9 +229,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
|
|||
try {
|
||||
len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
|
||||
} catch (ParseException pe) {
|
||||
CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
|
||||
e.initCause(pe);
|
||||
throw e;
|
||||
throw new CorruptIndexException("failed to parse int length (resource=" + in + ")", pe);
|
||||
}
|
||||
result.bytes = new byte[len];
|
||||
result.offset = 0;
|
||||
|
@ -263,9 +259,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
|
|||
try {
|
||||
len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
|
||||
} catch (ParseException pe) {
|
||||
CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
|
||||
e.initCause(pe);
|
||||
throw e;
|
||||
throw new CorruptIndexException("failed to parse int length (resource=" + in + ")", pe);
|
||||
}
|
||||
// skip past bytes
|
||||
byte bytes[] = new byte[len];
|
||||
|
@ -310,9 +304,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
|
|||
try {
|
||||
return (int) ordDecoder.parse(scratch.utf8ToString()).longValue()-1;
|
||||
} catch (ParseException pe) {
|
||||
CorruptIndexException e = new CorruptIndexException("failed to parse ord (resource=" + in + ")");
|
||||
e.initCause(pe);
|
||||
throw e;
|
||||
throw new CorruptIndexException("failed to parse ord (resource=" + in + ")", pe);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
|
@ -332,9 +324,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
|
|||
try {
|
||||
len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
|
||||
} catch (ParseException pe) {
|
||||
CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
|
||||
e.initCause(pe);
|
||||
throw e;
|
||||
throw new CorruptIndexException("failed to parse int length (resource=" + in + ")", pe);
|
||||
}
|
||||
result.bytes = new byte[len];
|
||||
result.offset = 0;
|
||||
|
@ -410,9 +400,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
|
|||
try {
|
||||
len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
|
||||
} catch (ParseException pe) {
|
||||
CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
|
||||
e.initCause(pe);
|
||||
throw e;
|
||||
throw new CorruptIndexException("failed to parse int length (resource=" + in + ")", pe);
|
||||
}
|
||||
result.bytes = new byte[len];
|
||||
result.offset = 0;
|
||||
|
|
|
@ -24,8 +24,13 @@ import java.io.IOException;
|
|||
* an inconsistency in the index.
|
||||
*/
|
||||
public class CorruptIndexException extends IOException {
|
||||
/** Sole constructor. */
|
||||
/** Create exception with a message only */
|
||||
public CorruptIndexException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/** Create exception with message and root cause. */
|
||||
public CorruptIndexException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1708,11 +1708,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{
|
|||
for(int i=0;i<size;i++) {
|
||||
final MergePolicy.OneMerge merge = mergeExceptions.get(i);
|
||||
if (merge.maxNumSegments != -1) {
|
||||
IOException err = new IOException("background merge hit exception: " + merge.segString(directory));
|
||||
final Throwable t = merge.getException();
|
||||
if (t != null)
|
||||
err.initCause(t);
|
||||
throw err;
|
||||
throw new IOException("background merge hit exception: " + merge.segString(directory), merge.getException());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1808,12 +1804,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{
|
|||
if (pendingMerges.contains(merge) || runningMerges.contains(merge)) {
|
||||
running = true;
|
||||
}
|
||||
Throwable t = merge.getException();
|
||||
if (t != null) {
|
||||
IOException ioe = new IOException("background merge hit exception: " + merge.segString(directory));
|
||||
ioe.initCause(t);
|
||||
throw ioe;
|
||||
}
|
||||
throw new IOException("background merge hit exception: " + merge.segString(directory), merge.getException());
|
||||
}
|
||||
|
||||
// If any of our merges are still running, wait:
|
||||
|
|
|
@ -38,8 +38,7 @@ public final class TwoPhaseCommitTool {
|
|||
|
||||
/** Sole constructor. */
|
||||
public PrepareCommitFailException(Throwable cause, TwoPhaseCommit obj) {
|
||||
super("prepareCommit() failed on " + obj);
|
||||
initCause(cause);
|
||||
super("prepareCommit() failed on " + obj, cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,8 +50,7 @@ public final class TwoPhaseCommitTool {
|
|||
|
||||
/** Sole constructor. */
|
||||
public CommitFailException(Throwable cause, TwoPhaseCommit obj) {
|
||||
super("commit() failed on " + obj);
|
||||
initCause(cause);
|
||||
super("commit() failed on " + obj, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,11 +86,7 @@ public abstract class Lock implements Closeable {
|
|||
if (failureReason != null) {
|
||||
reason += ": " + failureReason;
|
||||
}
|
||||
LockObtainFailedException e = new LockObtainFailedException(reason);
|
||||
if (failureReason != null) {
|
||||
e.initCause(failureReason);
|
||||
}
|
||||
throw e;
|
||||
throw new LockObtainFailedException(reason, failureReason);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(LOCK_POLL_INTERVAL);
|
||||
|
|
|
@ -30,4 +30,8 @@ public class LockObtainFailedException extends IOException {
|
|||
public LockObtainFailedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public LockObtainFailedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,9 +108,7 @@ public class XSLTResponseWriter implements QueryResponseWriter {
|
|||
try {
|
||||
t.transform(source, result);
|
||||
} catch(TransformerException te) {
|
||||
final IOException ioe = new IOException("XSLT transformation error");
|
||||
ioe.initCause(te);
|
||||
throw ioe;
|
||||
throw new IOException("XSLT transformation error", te);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ public final class SystemIdResolver implements EntityResolver, EntityResolver2 {
|
|||
return is;
|
||||
} catch (RuntimeException re) {
|
||||
// unfortunately XInclude fallback only works with IOException, but openResource() never throws that one
|
||||
throw (IOException) (new IOException(re.getMessage()).initCause(re));
|
||||
throw new IOException(re.getMessage(), re);
|
||||
}
|
||||
} else {
|
||||
// resolve all other URIs using the standard resolver
|
||||
|
|
|
@ -83,9 +83,7 @@ public class TransformerProvider {
|
|||
result = lastTemplates.newTransformer();
|
||||
} catch(TransformerConfigurationException tce) {
|
||||
log.error(getClass().getName(), "getTransformer", tce);
|
||||
final IOException ioe = new IOException("newTransformer fails ( " + lastFilename + ")");
|
||||
ioe.initCause(tce);
|
||||
throw ioe;
|
||||
throw new IOException("newTransformer fails ( " + lastFilename + ")", tce);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -114,9 +112,7 @@ public class TransformerProvider {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
log.error(getClass().getName(), "newTemplates", e);
|
||||
final IOException ioe = new IOException("Unable to initialize Templates '" + filename + "'");
|
||||
ioe.initCause(e);
|
||||
throw ioe;
|
||||
throw new IOException("Unable to initialize Templates '" + filename + "'", e);
|
||||
}
|
||||
|
||||
lastFilename = filename;
|
||||
|
|
Loading…
Reference in New Issue