diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index d4055dc5fca..191b7f239fc 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -122,6 +122,10 @@ API Changes * LUCENE-5965: CorruptIndexException requires a String or DataInput resource. (Robert Muir) +* LUCENE-5972: IndexFormatTooOldException and IndexFormatTooNewException now + extend from IOException. + (Ryan Ernst, Robert Muir) + Bug Fixes * LUCENE-5650: Enforce read-only access to any path outside the temporary 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 2b86f8f8e08..7995634417b 100644 --- a/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java +++ b/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java @@ -44,6 +44,6 @@ public class CorruptIndexException extends IOException { /** Create exception with message and root cause. */ public CorruptIndexException(String message, String resourceDescription, Throwable cause) { - super(message + " (resource=" + resourceDescription + ")", cause); + super(Objects.toString(message) + " (resource=" + resourceDescription + ")", cause); } } diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java b/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java index 696e2c22bbe..b23fb4d20e8 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java @@ -17,13 +17,16 @@ package org.apache.lucene.index; +import java.io.IOException; +import java.util.Objects; + import org.apache.lucene.store.DataInput; /** * This exception is thrown when Lucene detects * an index that is newer than this Lucene version. */ -public class IndexFormatTooNewException extends CorruptIndexException { +public class IndexFormatTooNewException extends IOException { /** Creates an {@code IndexFormatTooNewException} * @@ -34,9 +37,8 @@ public class IndexFormatTooNewException extends CorruptIndexException { * * @lucene.internal */ public IndexFormatTooNewException(String resourceDesc, int version, int minVersion, int maxVersion) { - super("Format version is not supported: " - + version + " (needs to be between " + minVersion + " and " + maxVersion + ")", resourceDesc); - assert resourceDesc != null; + super("Format version is not supported (resource " + resourceDesc + "): " + + version + " (needs to be between " + minVersion + " and " + maxVersion + ")"); } /** Creates an {@code IndexFormatTooNewException} @@ -48,7 +50,8 @@ public class IndexFormatTooNewException extends CorruptIndexException { * * @lucene.internal */ public IndexFormatTooNewException(DataInput in, int version, int minVersion, int maxVersion) { - this(in.toString(), version, minVersion, maxVersion); + this(Objects.toString(in), version, minVersion, maxVersion); } + } diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java b/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java index 0a1ce6016c9..150b7f107b0 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java @@ -17,13 +17,16 @@ package org.apache.lucene.index; +import java.io.IOException; +import java.util.Objects; + import org.apache.lucene.store.DataInput; /** * This exception is thrown when Lucene detects * an index that is too old for this Lucene version */ -public class IndexFormatTooOldException extends CorruptIndexException { +public class IndexFormatTooOldException extends IOException { /** Creates an {@code IndexFormatTooOldException}. * @@ -32,21 +35,20 @@ public class IndexFormatTooOldException extends CorruptIndexException { * * @lucene.internal */ public IndexFormatTooOldException(String resourceDesc, String version) { - super("Format version is not supported: " + - version + ". This version of Lucene only supports indexes created with release 4.0 and later.", resourceDesc); - assert resourceDesc != null; + super("Format version is not supported (resource " + resourceDesc + "): " + + version + ". This version of Lucene only supports indexes created with release 4.0 and later."); } /** Creates an {@code IndexFormatTooOldException}. * * @param in the open file that's too old * @param version the version of the file that was too old - * + * * @lucene.internal */ public IndexFormatTooOldException(DataInput in, String version) { - this(in.toString(), version); + this(Objects.toString(in), version); } - + /** Creates an {@code IndexFormatTooOldException}. * * @param resourceDesc describes the file that was too old @@ -56,10 +58,9 @@ public class IndexFormatTooOldException extends CorruptIndexException { * * @lucene.internal */ public IndexFormatTooOldException(String resourceDesc, int version, int minVersion, int maxVersion) { - super("Format version is not supported: " + + super("Format version is not supported (resource " + resourceDesc + "): " + version + " (needs to be between " + minVersion + " and " + maxVersion + - "). This version of Lucene only supports indexes created with release 4.0 and later.", resourceDesc); - assert resourceDesc != null; + "). This version of Lucene only supports indexes created with release 4.0 and later."); } /** Creates an {@code IndexFormatTooOldException}. @@ -71,6 +72,6 @@ public class IndexFormatTooOldException extends CorruptIndexException { * * @lucene.internal */ public IndexFormatTooOldException(DataInput in, int version, int minVersion, int maxVersion) { - this(in.toString(), version, minVersion, maxVersion); + this(Objects.toString(in), version, minVersion, maxVersion); } }