mirror of https://github.com/apache/lucene.git
LUCENE-6714: Expose exception details via getters on CorruptedIndex-, IndexTooOld-, IndexTooOldException
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1693929 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0398139b1a
commit
bf853057ce
|
@ -502,6 +502,19 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
|
||||||
reader = DirectoryReader.open(dir);
|
reader = DirectoryReader.open(dir);
|
||||||
fail("DirectoryReader.open should not pass for "+unsupportedNames[i]);
|
fail("DirectoryReader.open should not pass for "+unsupportedNames[i]);
|
||||||
} catch (IndexFormatTooOldException e) {
|
} 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
|
// pass
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.out.println("TEST: got expected exc:");
|
System.out.println("TEST: got expected exc:");
|
||||||
|
@ -516,6 +529,19 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
|
||||||
writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setCommitOnClose(false));
|
writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setCommitOnClose(false));
|
||||||
fail("IndexWriter creation should not pass for "+unsupportedNames[i]);
|
fail("IndexWriter creation should not pass for "+unsupportedNames[i]);
|
||||||
} catch (IndexFormatTooOldException e) {
|
} 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
|
// pass
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.out.println("TEST: got expected exc:");
|
System.out.println("TEST: got expected exc:");
|
||||||
|
|
|
@ -98,6 +98,7 @@ public class BuildMaxPositionIndex {
|
||||||
try {
|
try {
|
||||||
w.forceMerge(1);
|
w.forceMerge(1);
|
||||||
} catch (CorruptIndexException cie) {
|
} catch (CorruptIndexException cie) {
|
||||||
|
assertEquals(cie.getMessage(), new CorruptIndexException(cie.getOriginalMessage(), cie.getResourceDescription()).getMessage());
|
||||||
// SerialMergeScheduler
|
// SerialMergeScheduler
|
||||||
assertTrue("got message " + cie.getMessage(),
|
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)"));
|
cie.getMessage().contains("position=2147483647 is too large (> IndexWriter.MAX_POSITION=2147483519), field=\"foo\" doc=0 (resource=PerFieldPostings(segment=_0 formats=1)"));
|
||||||
|
|
|
@ -28,6 +28,10 @@ import org.apache.lucene.store.DataOutput;
|
||||||
* an inconsistency in the index.
|
* an inconsistency in the index.
|
||||||
*/
|
*/
|
||||||
public class CorruptIndexException extends IOException {
|
public class CorruptIndexException extends IOException {
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
private final String resourceDescription;
|
||||||
|
|
||||||
/** Create exception with a message only */
|
/** Create exception with a message only */
|
||||||
public CorruptIndexException(String message, DataInput input) {
|
public CorruptIndexException(String message, DataInput input) {
|
||||||
this(message, input, null);
|
this(message, input, null);
|
||||||
|
@ -56,5 +60,21 @@ public class CorruptIndexException extends IOException {
|
||||||
/** Create exception with message and root cause. */
|
/** Create exception with message and root cause. */
|
||||||
public CorruptIndexException(String message, String resourceDescription, Throwable cause) {
|
public CorruptIndexException(String message, String resourceDescription, Throwable cause) {
|
||||||
super(Objects.toString(message) + " (resource=" + resourceDescription + ")", 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,30 +28,65 @@ import org.apache.lucene.store.DataInput;
|
||||||
*/
|
*/
|
||||||
public class IndexFormatTooNewException extends IOException {
|
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}
|
/** Creates an {@code IndexFormatTooNewException}
|
||||||
*
|
*
|
||||||
* @param resourceDesc describes 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 old
|
* @param version the version of the file that was too new
|
||||||
* @param minVersion the minimum version accepted
|
* @param minVersion the minimum version accepted
|
||||||
* @param maxVersion the maxium version accepted
|
* @param maxVersion the maximum version accepted
|
||||||
*
|
*
|
||||||
* @lucene.internal */
|
* @lucene.internal */
|
||||||
public IndexFormatTooNewException(String resourceDesc, int version, int minVersion, int maxVersion) {
|
public IndexFormatTooNewException(String resourceDescription, int version, int minVersion, int maxVersion) {
|
||||||
super("Format version is not supported (resource " + resourceDesc + "): "
|
super("Format version is not supported (resource " + resourceDescription + "): "
|
||||||
+ version + " (needs to be between " + minVersion + " and " + maxVersion + ")");
|
+ version + " (needs to be between " + minVersion + " and " + maxVersion + ")");
|
||||||
|
this.resourceDescription = resourceDescription;
|
||||||
|
this.version = version;
|
||||||
|
this.minVersion = minVersion;
|
||||||
|
this.maxVersion = maxVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates an {@code IndexFormatTooNewException}
|
/** Creates an {@code IndexFormatTooNewException}
|
||||||
*
|
*
|
||||||
* @param in the open file that's too old
|
* @param in the open file that's too new
|
||||||
* @param version the version of the file that was too old
|
* @param version the version of the file that was too new
|
||||||
* @param minVersion the minimum version accepted
|
* @param minVersion the minimum version accepted
|
||||||
* @param maxVersion the maxium version accepted
|
* @param maxVersion the maximum version accepted
|
||||||
*
|
*
|
||||||
* @lucene.internal */
|
* @lucene.internal */
|
||||||
public IndexFormatTooNewException(DataInput in, int version, int minVersion, int maxVersion) {
|
public IndexFormatTooNewException(DataInput in, int version, int minVersion, int maxVersion) {
|
||||||
this(Objects.toString(in), version, minVersion, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,39 +28,57 @@ import org.apache.lucene.store.DataInput;
|
||||||
*/
|
*/
|
||||||
public class IndexFormatTooOldException extends IOException {
|
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}.
|
/** 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 reason the reason for this exception if the version is not available
|
||||||
*
|
*
|
||||||
* @lucene.internal */
|
* @lucene.internal */
|
||||||
public IndexFormatTooOldException(String resourceDesc, String version) {
|
public IndexFormatTooOldException(String resourceDescription, String reason) {
|
||||||
super("Format version is not supported (resource " + resourceDesc + "): " +
|
super("Format version is not supported (resource " + resourceDescription + "): " +
|
||||||
version + ". This version of Lucene only supports indexes created with release 4.0 and later.");
|
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}.
|
/** Creates an {@code IndexFormatTooOldException}.
|
||||||
*
|
*
|
||||||
* @param in the open file that's too old
|
* @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 */
|
* @lucene.internal */
|
||||||
public IndexFormatTooOldException(DataInput in, String version) {
|
public IndexFormatTooOldException(DataInput in, String reason) {
|
||||||
this(Objects.toString(in), version);
|
this(Objects.toString(in), reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates an {@code IndexFormatTooOldException}.
|
/** 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 version the version of the file that was too old
|
||||||
* @param minVersion the minimum version accepted
|
* @param minVersion the minimum version accepted
|
||||||
* @param maxVersion the maxium version accepted
|
* @param maxVersion the maximum version accepted
|
||||||
*
|
*
|
||||||
* @lucene.internal */
|
* @lucene.internal */
|
||||||
public IndexFormatTooOldException(String resourceDesc, int version, int minVersion, int maxVersion) {
|
public IndexFormatTooOldException(String resourceDescription, int version, int minVersion, int maxVersion) {
|
||||||
super("Format version is not supported (resource " + resourceDesc + "): " +
|
super("Format version is not supported (resource " + resourceDescription + "): " +
|
||||||
version + " (needs to be between " + minVersion + " and " + maxVersion +
|
version + " (needs to be between " + minVersion + " and " + maxVersion +
|
||||||
"). This version of Lucene only supports indexes created with release 4.0 and later.");
|
"). 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}.
|
/** Creates an {@code IndexFormatTooOldException}.
|
||||||
|
@ -68,10 +86,51 @@ public class IndexFormatTooOldException extends IOException {
|
||||||
* @param in the open file that's too old
|
* @param in the open file that's too old
|
||||||
* @param version the version of the file that was too old
|
* @param version the version of the file that was too old
|
||||||
* @param minVersion the minimum version accepted
|
* @param minVersion the minimum version accepted
|
||||||
* @param maxVersion the maxium version accepted
|
* @param maxVersion the maximum version accepted
|
||||||
*
|
*
|
||||||
* @lucene.internal */
|
* @lucene.internal */
|
||||||
public IndexFormatTooOldException(DataInput in, int version, int minVersion, int maxVersion) {
|
public IndexFormatTooOldException(DataInput in, int version, int minVersion, int maxVersion) {
|
||||||
this(Objects.toString(in), version, minVersion, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue