You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2015/08/03 18:22:10 UTC
svn commit: r1693929 - in /lucene/dev/trunk/lucene:
backward-codecs/src/test/org/apache/lucene/index/
core/src/java/org/apache/lucene/index/
Author: simonw
Date: Mon Aug 3 16:22:10 2015
New Revision: 1693929
URL: http://svn.apache.org/r1693929
Log:
LUCENE-6714: Expose exception details via getters on CorruptedIndex-, IndexTooOld-, IndexTooOldException
Modified:
lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java
Modified: lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1693929&r1=1693928&r2=1693929&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Mon Aug 3 16:22:10 2015
@@ -502,6 +502,19 @@ public class TestBackwardsCompatibility
reader = DirectoryReader.open(dir);
fail("DirectoryReader.open should not pass for "+unsupportedNames[i]);
} catch (IndexFormatTooOldException e) {
+ if (e.getReason() != null) {
+ assertNull(e.getVersion());
+ assertNull(e.getMinVersion());
+ assertNull(e.getMaxVersion());
+ assertEquals(e.getMessage(), new IndexFormatTooOldException(e.getResourceDescription(), e.getReason()).getMessage());
+ } else {
+ assertNotNull(e.getVersion());
+ assertNotNull(e.getMinVersion());
+ assertNotNull(e.getMaxVersion());
+ assertTrue(e.getMessage(), e.getMaxVersion() >= e.getMinVersion());
+ assertTrue(e.getMessage(), e.getMaxVersion() < e.getVersion() || e.getVersion() < e.getMinVersion());
+ assertEquals(e.getMessage(), new IndexFormatTooOldException(e.getResourceDescription(), e.getVersion(), e.getMinVersion(), e.getMaxVersion()).getMessage());
+ }
// pass
if (VERBOSE) {
System.out.println("TEST: got expected exc:");
@@ -516,6 +529,19 @@ public class TestBackwardsCompatibility
writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setCommitOnClose(false));
fail("IndexWriter creation should not pass for "+unsupportedNames[i]);
} catch (IndexFormatTooOldException e) {
+ if (e.getReason() != null) {
+ assertNull(e.getVersion());
+ assertNull(e.getMinVersion());
+ assertNull(e.getMaxVersion());
+ assertEquals(e.getMessage(), new IndexFormatTooOldException(e.getResourceDescription(), e.getReason()).getMessage());
+ } else {
+ assertNotNull(e.getVersion());
+ assertNotNull(e.getMinVersion());
+ assertNotNull(e.getMaxVersion());
+ assertTrue(e.getMessage(), e.getMaxVersion() >= e.getMinVersion());
+ assertTrue(e.getMessage(), e.getMaxVersion() < e.getVersion() || e.getVersion() < e.getMinVersion());
+ assertEquals(e.getMessage(), new IndexFormatTooOldException(e.getResourceDescription(), e.getVersion(), e.getMinVersion(), e.getMaxVersion()).getMessage());
+ }
// pass
if (VERBOSE) {
System.out.println("TEST: got expected exc:");
Modified: lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java?rev=1693929&r1=1693928&r2=1693929&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java (original)
+++ lucene/dev/trunk/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java Mon Aug 3 16:22:10 2015
@@ -98,6 +98,7 @@ public class BuildMaxPositionIndex {
try {
w.forceMerge(1);
} catch (CorruptIndexException cie) {
+ assertEquals(cie.getMessage(), new CorruptIndexException(cie.getOriginalMessage(), cie.getResourceDescription()).getMessage());
// SerialMergeScheduler
assertTrue("got message " + cie.getMessage(),
cie.getMessage().contains("position=2147483647 is too large (> IndexWriter.MAX_POSITION=2147483519), field=\"foo\" doc=0 (resource=PerFieldPostings(segment=_0 formats=1)"));
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java?rev=1693929&r1=1693928&r2=1693929&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java Mon Aug 3 16:22:10 2015
@@ -28,6 +28,10 @@ import org.apache.lucene.store.DataOutpu
* an inconsistency in the index.
*/
public class CorruptIndexException extends IOException {
+
+ private final String message;
+ private final String resourceDescription;
+
/** Create exception with a message only */
public CorruptIndexException(String message, DataInput input) {
this(message, input, null);
@@ -56,5 +60,21 @@ public class CorruptIndexException exten
/** Create exception with message and root cause. */
public CorruptIndexException(String message, String resourceDescription, Throwable cause) {
super(Objects.toString(message) + " (resource=" + resourceDescription + ")", cause);
+ this.resourceDescription = resourceDescription;
+ this.message = message;
+ }
+
+ /**
+ * Returns a description of the file that was corrupted
+ */
+ public String getResourceDescription() {
+ return resourceDescription;
+ }
+
+ /**
+ * Returns the original exception message without the corrupted file description.
+ */
+ public String getOriginalMessage() {
+ return message;
}
}
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java?rev=1693929&r1=1693928&r2=1693929&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java Mon Aug 3 16:22:10 2015
@@ -28,30 +28,65 @@ import org.apache.lucene.store.DataInput
*/
public class IndexFormatTooNewException extends IOException {
+ private final String resourceDescription;
+ private final int version;
+ private final int minVersion;
+ private final int maxVersion;
+
/** Creates an {@code IndexFormatTooNewException}
*
- * @param resourceDesc describes the file that was too old
- * @param version the version of the file that was too old
+ * @param resourceDescription describes the file that was too new
+ * @param version the version of the file that was too new
* @param minVersion the minimum version accepted
- * @param maxVersion the maxium version accepted
+ * @param maxVersion the maximum version accepted
*
* @lucene.internal */
- public IndexFormatTooNewException(String resourceDesc, int version, int minVersion, int maxVersion) {
- super("Format version is not supported (resource " + resourceDesc + "): "
+ public IndexFormatTooNewException(String resourceDescription, int version, int minVersion, int maxVersion) {
+ super("Format version is not supported (resource " + resourceDescription + "): "
+ version + " (needs to be between " + minVersion + " and " + maxVersion + ")");
+ this.resourceDescription = resourceDescription;
+ this.version = version;
+ this.minVersion = minVersion;
+ this.maxVersion = maxVersion;
}
/** Creates an {@code IndexFormatTooNewException}
*
- * @param in the open file that's too old
- * @param version the version of the file that was too old
+ * @param in the open file that's too new
+ * @param version the version of the file that was too new
* @param minVersion the minimum version accepted
- * @param maxVersion the maxium version accepted
+ * @param maxVersion the maximum version accepted
*
* @lucene.internal */
public IndexFormatTooNewException(DataInput in, int version, int minVersion, int maxVersion) {
this(Objects.toString(in), version, minVersion, maxVersion);
}
+ /**
+ * Returns a description of the file that was too new
+ */
+ public String getResourceDescription() {
+ return resourceDescription;
+ }
+
+ /**
+ * Returns the version of the file that was too new
+ */
+ public int getVersion() {
+ return version;
+ }
+ /**
+ * Returns the maximum version accepted
+ */
+ public int getMaxVersion() {
+ return maxVersion;
+ }
+
+ /**
+ * Returns the minimum version accepted
+ */
+ public int getMinVersion() {
+ return minVersion;
+ }
}
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java?rev=1693929&r1=1693928&r2=1693929&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java Mon Aug 3 16:22:10 2015
@@ -28,39 +28,57 @@ import org.apache.lucene.store.DataInput
*/
public class IndexFormatTooOldException extends IOException {
+ private final String resourceDescription;
+ private final String reason;
+ private final Integer version;
+ private final Integer minVersion;
+ private final Integer maxVersion;
+
+
/** Creates an {@code IndexFormatTooOldException}.
*
- * @param resourceDesc describes the file that was too old
- * @param version the version of the file that was too old
- *
+ * @param resourceDescription describes the file that was too old
+ * @param reason the reason for this exception if the version is not available
+ *
* @lucene.internal */
- public IndexFormatTooOldException(String resourceDesc, String version) {
- super("Format version is not supported (resource " + resourceDesc + "): " +
- version + ". This version of Lucene only supports indexes created with release 4.0 and later.");
+ public IndexFormatTooOldException(String resourceDescription, String reason) {
+ super("Format version is not supported (resource " + resourceDescription + "): " +
+ reason + ". This version of Lucene only supports indexes created with release 4.0 and later.");
+ this.resourceDescription = resourceDescription;
+ this.reason = reason;
+ this.version = null;
+ this.minVersion = null;
+ this.maxVersion = null;
+
}
/** Creates an {@code IndexFormatTooOldException}.
*
* @param in the open file that's too old
- * @param version the version of the file that was too old
+ * @param reason the reason for this exception if the version is not available
*
* @lucene.internal */
- public IndexFormatTooOldException(DataInput in, String version) {
- this(Objects.toString(in), version);
+ public IndexFormatTooOldException(DataInput in, String reason) {
+ this(Objects.toString(in), reason);
}
/** Creates an {@code IndexFormatTooOldException}.
*
- * @param resourceDesc describes the file that was too old
+ * @param resourceDescription describes the file that was too old
* @param version the version of the file that was too old
* @param minVersion the minimum version accepted
- * @param maxVersion the maxium version accepted
+ * @param maxVersion the maximum version accepted
*
* @lucene.internal */
- public IndexFormatTooOldException(String resourceDesc, int version, int minVersion, int maxVersion) {
- super("Format version is not supported (resource " + resourceDesc + "): " +
+ public IndexFormatTooOldException(String resourceDescription, int version, int minVersion, int maxVersion) {
+ super("Format version is not supported (resource " + resourceDescription + "): " +
version + " (needs to be between " + minVersion + " and " + maxVersion +
"). This version of Lucene only supports indexes created with release 4.0 and later.");
+ this.resourceDescription = resourceDescription;
+ this.version = version;
+ this.minVersion = minVersion;
+ this.maxVersion = maxVersion;
+ this.reason = null;
}
/** Creates an {@code IndexFormatTooOldException}.
@@ -68,10 +86,51 @@ public class IndexFormatTooOldException
* @param in the open file that's too old
* @param version the version of the file that was too old
* @param minVersion the minimum version accepted
- * @param maxVersion the maxium version accepted
+ * @param maxVersion the maximum version accepted
*
* @lucene.internal */
public IndexFormatTooOldException(DataInput in, int version, int minVersion, int maxVersion) {
this(Objects.toString(in), version, minVersion, maxVersion);
}
+
+ /**
+ * Returns a description of the file that was too old
+ */
+ public String getResourceDescription() {
+ return resourceDescription;
+ }
+
+ /**
+ * Returns an optional reason for this exception if the version information was not available. Otherwise <code>null</code>
+ */
+ public String getReason() {
+ return reason;
+ }
+
+ /**
+ * Returns the version of the file that was too old.
+ * This method will return <code>null</code> if an alternative {@link #getReason()}
+ * is provided.
+ */
+ public Integer getVersion() {
+ return version;
+ }
+
+ /**
+ * Returns the maximum version accepted.
+ * This method will return <code>null</code> if an alternative {@link #getReason()}
+ * is provided.
+ */
+ public Integer getMaxVersion() {
+ return maxVersion;
+ }
+
+ /**
+ * Returns the minimum version accepted
+ * This method will return <code>null</code> if an alternative {@link #getReason()}
+ * is provided.
+ */
+ public Integer getMinVersion() {
+ return minVersion;
+ }
}