Apache Lucene open-source search software
Simplify for Java 7, which has support for new IOException(message, cause)
Uwe Schindler67b7b43b4936
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/StreamUtils.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/StreamUtils.javaindex 6a3dd3cfb81..fbcec4d784d 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/StreamUtils.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/StreamUtils.java@@ -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);}}}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.javaindex 07a804a46e8..55fb1ee052a 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java@@ -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 notreturn 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 bytesbyte 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;diff --git a/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java b/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.javaindex 583a4bac7ef..ce495ea08ce 100644--- a/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java+++ b/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java@@ -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);+ }}diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex a6275e1164b..a0d4c71f925 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -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:diff --git a/lucene/core/src/java/org/apache/lucene/index/TwoPhaseCommitTool.java b/lucene/core/src/java/org/apache/lucene/index/TwoPhaseCommitTool.javaindex 25f4160a3ef..ee8f8b25a85 100644--- a/lucene/core/src/java/org/apache/lucene/index/TwoPhaseCommitTool.java+++ b/lucene/core/src/java/org/apache/lucene/index/TwoPhaseCommitTool.java@@ -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);}}diff --git a/lucene/core/src/java/org/apache/lucene/store/Lock.java b/lucene/core/src/java/org/apache/lucene/store/Lock.javaindex dd00a92c4de..a59c59b1fa8 100644--- a/lucene/core/src/java/org/apache/lucene/store/Lock.java+++ b/lucene/core/src/java/org/apache/lucene/store/Lock.java@@ -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);diff --git a/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java b/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.javaindex ed716f1bfd0..14b0b5403f3 100644--- a/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java+++ b/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java@@ -30,4 +30,8 @@ public class LockObtainFailedException extends IOException {public LockObtainFailedException(String message) {super(message);}++ public LockObtainFailedException(String message, Throwable cause) {+ super(message, cause);+ }}diff --git a/solr/core/src/java/org/apache/solr/response/XSLTResponseWriter.java b/solr/core/src/java/org/apache/solr/response/XSLTResponseWriter.javaindex f7f74106c96..4ff55cb9598 100644--- a/solr/core/src/java/org/apache/solr/response/XSLTResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/XSLTResponseWriter.java@@ -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);}}diff --git a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.javaindex 2263f9fcbc6..07f20724040 100644--- a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java+++ b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java@@ -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 resolverdiff --git a/solr/core/src/java/org/apache/solr/util/xslt/TransformerProvider.java b/solr/core/src/java/org/apache/solr/util/xslt/TransformerProvider.javaindex 527d15e65fd..87ab2f93a3c 100644--- a/solr/core/src/java/org/apache/solr/util/xslt/TransformerProvider.java+++ b/solr/core/src/java/org/apache/solr/util/xslt/TransformerProvider.java@@ -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;