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
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.java
index 6a3dd3c..fbcec4d 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 @@
       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.java
index 07a804a..55fb1ee 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 @@
           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 @@
           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 @@
           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 @@
           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 @@
           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 @@
           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.java
index 583a4ba..ce495ea 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 @@
  * 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.java
index a6275e1..a0d4c71 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 @@
             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 @@
             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.java
index 25f4160..ee8f8b2 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 @@
 
     /** 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 @@
 
     /** 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.java
index dd00a92..a59c59b 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 @@
         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.java
index ed716f1..14b0b54 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 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.java
index f7f7410..4ff55cb 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 @@
     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.java
index 2263f9f..07f2072 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 @@
           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
diff --git a/solr/core/src/java/org/apache/solr/util/xslt/TransformerProvider.java b/solr/core/src/java/org/apache/solr/util/xslt/TransformerProvider.java
index 527d15e..87ab2f9 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 @@
       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 @@
       }
     } 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;