List of usage examples for org.apache.lucene.index IndexFormatTooNewException IndexFormatTooNewException
public IndexFormatTooNewException(DataInput in, int version, int minVersion, int maxVersion)
From source file:org.codelibs.elasticsearch.common.io.stream.StreamInput.java
License:Apache License
public <T extends Exception> T readException() throws IOException { if (readBoolean()) { int key = readVInt(); switch (key) { case 0://from w w w .j av a 2 s. c o m final int ord = readVInt(); return (T) ElasticsearchException.readException(this, ord); case 1: String msg1 = readOptionalString(); String resource1 = readOptionalString(); return (T) readStackTrace(new CorruptIndexException(msg1, resource1, readException()), this); case 2: String resource2 = readOptionalString(); int version2 = readInt(); int minVersion2 = readInt(); int maxVersion2 = readInt(); return (T) readStackTrace( new IndexFormatTooNewException(resource2, version2, minVersion2, maxVersion2), this); case 3: String resource3 = readOptionalString(); if (readBoolean()) { int version3 = readInt(); int minVersion3 = readInt(); int maxVersion3 = readInt(); return (T) readStackTrace( new IndexFormatTooOldException(resource3, version3, minVersion3, maxVersion3), this); } else { String version3 = readOptionalString(); return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3), this); } case 4: return (T) readStackTrace(new NullPointerException(readOptionalString()), this); case 5: return (T) readStackTrace(new NumberFormatException(readOptionalString()), this); case 6: return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readException()), this); case 7: return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readException()), this); case 8: return (T) readStackTrace(new EOFException(readOptionalString()), this); case 9: return (T) readStackTrace(new SecurityException(readOptionalString(), readException()), this); case 10: return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this); case 11: return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this); case 12: return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this); case 13: final int subclass = readVInt(); final String file = readOptionalString(); final String other = readOptionalString(); final String reason = readOptionalString(); readOptionalString(); // skip the msg - it's composed from file, other and reason final Exception exception; switch (subclass) { case 0: exception = new NoSuchFileException(file, other, reason); break; case 1: exception = new NotDirectoryException(file); break; case 2: exception = new DirectoryNotEmptyException(file); break; case 3: exception = new AtomicMoveNotSupportedException(file, other, reason); break; case 4: exception = new FileAlreadyExistsException(file, other, reason); break; case 5: exception = new AccessDeniedException(file, other, reason); break; case 6: exception = new FileSystemLoopException(file); break; case 7: exception = new FileSystemException(file, other, reason); break; default: throw new IllegalStateException("unknown FileSystemException with index " + subclass); } return (T) readStackTrace(exception, this); case 14: return (T) readStackTrace(new IllegalStateException(readOptionalString(), readException()), this); case 15: return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readException()), this); case 16: return (T) readStackTrace(new InterruptedException(readOptionalString()), this); case 17: return (T) readStackTrace(new IOException(readOptionalString(), readException()), this); default: assert false : "no such exception for id: " + key; } } return null; }
From source file:org.elasticsearch.ESExceptionTests.java
License:Apache License
public void testWriteThrowable() throws IOException { Throwable[] causes = new Throwable[] { new IllegalStateException("foobar"), new IllegalArgumentException("alalaal"), new NullPointerException("boom"), new EOFException("dadada"), new ElasticsearchSecurityException("nono!"), new NumberFormatException("not a number"), new CorruptIndexException("baaaam booom", "this is my resource"), new IndexFormatTooNewException("tooo new", 1, 2, 3), new IndexFormatTooOldException("tooo new", 1, 2, 3), new IndexFormatTooOldException("tooo new", "very old version"), new ArrayIndexOutOfBoundsException("booom"), new StringIndexOutOfBoundsException("booom"), new FileNotFoundException("booom"), new NoSuchFileException("booom"), new AssertionError("booom", new NullPointerException()), new OutOfMemoryError("no memory left"), new AlreadyClosedException("closed!!", new NullPointerException()), new LockObtainFailedException("can't lock directory", new NullPointerException()), new Throwable("this exception is unknown", new QueryParsingException(new Index("foo"), 1, 2, "foobar", null)), // somethin unknown };/*from www . j av a2 s .c om*/ for (Throwable t : causes) { BytesStreamOutput out = new BytesStreamOutput(); ElasticsearchException ex = new ElasticsearchException("topLevel", t); out.writeThrowable(ex); StreamInput in = StreamInput.wrap(out.bytes()); ElasticsearchException e = in.readThrowable(); assertEquals(e.getMessage(), ex.getMessage()); assertTrue("Expected: " + e.getCause().getMessage() + " to contain: " + ex.getCause().getClass().getName() + " but it didn't", e.getCause().getMessage().contains(ex.getCause().getMessage())); if (ex.getCause().getClass() != Throwable.class) { // throwable is not directly mapped assertEquals(e.getCause().getClass(), ex.getCause().getClass()); } else { assertEquals(e.getCause().getClass(), NotSerializableExceptionWrapper.class); } assertArrayEquals(e.getStackTrace(), ex.getStackTrace()); assertTrue(e.getStackTrace().length > 1); ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(getRandom()), t); ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(getRandom()), ex); ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(getRandom()), e); } }