Skip to content

Commit

Permalink
Fix NPE in Indices#checkForReopened(IndexMetaData)
Browse files Browse the repository at this point in the history
Fixes #2628
  • Loading branch information
Jochen Schalanda committed Aug 8, 2016
1 parent 8130b7e commit fd009b0
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -360,12 +361,8 @@ public void reopenIndex(String index) {
}

public boolean isReopened(String indexName) {
ClusterState clusterState = c.admin().cluster().state(new ClusterStateRequest()).actionGet().getState();
IndexMetaData metaData = clusterState.getMetaData().getIndices().get(indexName);

if (metaData == null) {
return false;
}
final ClusterState clusterState = c.admin().cluster().state(new ClusterStateRequest()).actionGet().getState();
final IndexMetaData metaData = clusterState.getMetaData().getIndices().get(indexName);

return checkForReopened(metaData);
}
Expand All @@ -374,12 +371,15 @@ public Map<String, Boolean> areReopened(Collection<String> indices) {
final ClusterStateResponse clusterState = c.admin().cluster().prepareState().all().get();
final ImmutableOpenMap<String, IndexMetaData> indicesMetaData = clusterState.getState().getMetaData().getIndices();
return indices.stream().collect(
Collectors.toMap((index) -> index, (index) -> checkForReopened(indicesMetaData.get(index)))
Collectors.toMap(index -> index, index -> checkForReopened(indicesMetaData.get(index)))
);
}

protected Boolean checkForReopened(IndexMetaData metaData) {
return metaData.getSettings().getAsBoolean("index." + REOPENED_INDEX_SETTING, false);
private boolean checkForReopened(@Nullable IndexMetaData metaData) {
return Optional.ofNullable(metaData)
.map(IndexMetaData::getSettings)
.map(settings -> settings.getAsBoolean("index." + REOPENED_INDEX_SETTING, false))
.orElse(false);
}

public Set<String> getClosedIndices() {
Expand Down

0 comments on commit fd009b0

Please sign in to comment.