Fix compilation in Eclipse (backport of #54275) (#54284)

These mock calls cause Eclipse to think that `Exception` can be thrown
because `CheckedFunction`'s lower bound is `Exception`. This makes
Eclipse happy.
This commit is contained in:
Nik Everett 2020-03-26 12:53:13 -04:00 committed by GitHub
parent fc92bf4208
commit b6a8de0d89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -357,7 +357,13 @@ public class MetaDataRolloverServiceTests extends ESTestCase {
}
}
private IndicesService mockIndicesServices() throws java.io.IOException {
private IndicesService mockIndicesServices() throws Exception {
/*
* Throws Exception because Eclipse uses the lower bound for
* CheckedFunction's exception type so it thinks the "when" call
* can throw Exception. javac seems to be ok inferring something
* else.
*/
IndicesService indicesService = mock(IndicesService.class);
when(indicesService.withTempIndexService(any(IndexMetaData.class), any(CheckedFunction.class)))
.then(invocationOnMock -> {

View File

@ -93,7 +93,6 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportService;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -173,7 +172,13 @@ public class ClusterStateChanges {
//noinspection unchecked
return ((CheckedFunction) invocationOnMock.getArguments()[1]).apply(indexService);
});
} catch (IOException e) {
} catch (Exception e) {
/*
* Catch Exception because Eclipse uses the lower bound for
* CheckedFunction's exception type so it thinks the "when" call
* can throw Exception. javac seems to be ok inferring something
* else.
*/
throw new IllegalStateException(e);
}