mirror of https://github.com/apache/lucene.git
SOLR-13407: Fix NPE and be consistent about returning empty instead of null properties.
This commit is contained in:
parent
f77c56dbc6
commit
ced0243a3e
|
@ -92,9 +92,9 @@ public class MaintainCategoryRoutedAliasCmd extends AliasCmd {
|
|||
final ZkStateReader.AliasesManager aliasesManager = ocmh.zkStateReader.aliasesManager;
|
||||
final Aliases aliases = aliasesManager.getAliases();
|
||||
final Map<String, String> aliasMetadata = aliases.getCollectionAliasProperties(aliasName);
|
||||
if (aliasMetadata == null) {
|
||||
if (aliasMetadata.isEmpty()) {
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||
"Alias " + aliasName + " does not exist."); // if it did exist, we'd have a non-null map
|
||||
"Alias " + aliasName + " does not exist or is not a routed alias."); // if it did exist, we'd have a non-null map
|
||||
}
|
||||
final CategoryRoutedAlias categoryRoutedAlias = (CategoryRoutedAlias) RoutedAlias.fromProps(aliasName, aliasMetadata);
|
||||
|
||||
|
|
|
@ -103,9 +103,9 @@ public class MaintainTimeRoutedAliasCmd extends AliasCmd {
|
|||
final ZkStateReader.AliasesManager aliasesManager = ocmh.zkStateReader.aliasesManager;
|
||||
final Aliases aliases = aliasesManager.getAliases();
|
||||
final Map<String, String> aliasMetadata = aliases.getCollectionAliasProperties(aliasName);
|
||||
if (aliasMetadata == null) {
|
||||
if (aliasMetadata.isEmpty()) {
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||
"Alias " + aliasName + " does not exist."); // if it did exist, we'd have a non-null map
|
||||
"Alias " + aliasName + " does not exist or is not a routed alias."); // if it did exist, we'd have a non-null map
|
||||
}
|
||||
final TimeRoutedAlias timeRoutedAlias = new TimeRoutedAlias(aliasName, aliasMetadata);
|
||||
|
||||
|
|
|
@ -698,7 +698,7 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
|
|||
Map<String,Map<String,String>> meta = new LinkedHashMap<>();
|
||||
for (String alias : aliases.getCollectionAliasListMap().keySet()) {
|
||||
Map<String, String> collectionAliasProperties = aliases.getCollectionAliasProperties(alias);
|
||||
if (collectionAliasProperties != null) {
|
||||
if (!collectionAliasProperties.isEmpty()) {
|
||||
meta.put(alias, collectionAliasProperties);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class RoutedAliasUpdateProcessor extends UpdateRequestProcessor {
|
|||
private static Map<String, String> getAliasProps(SolrQueryRequest req, String aliasName) {
|
||||
ZkController zkController = req.getCore().getCoreContainer().getZkController();
|
||||
final Map<String, String> aliasProperties = zkController.getZkStateReader().getAliases().getCollectionAliasProperties(aliasName);
|
||||
if (aliasProperties == null) {
|
||||
if (aliasProperties.isEmpty()) {
|
||||
throw RoutedAlias.newAliasMustExistException(aliasName); // if it did exist, we'd have a non-null map
|
||||
}
|
||||
return aliasProperties;
|
||||
|
|
|
@ -246,7 +246,7 @@ public abstract class BaseHttpClusterStateProvider implements ClusterStateProvid
|
|||
@Override
|
||||
public Map<String, String> getAliasProperties(String alias) {
|
||||
getAliases(false);
|
||||
return Collections.unmodifiableMap(aliasProperties.get(alias));
|
||||
return Collections.unmodifiableMap(aliasProperties.getOrDefault(alias, Collections.emptyMap()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -160,11 +160,10 @@ public class Aliases {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable Map of properties for a given alias. If an alias by the given name
|
||||
* exists, this method will never return null.
|
||||
* Returns an unmodifiable Map of properties for a given alias. This method will never return null.
|
||||
*
|
||||
* @param alias the name of an alias also found as a key in {@link #getCollectionAliasListMap()}
|
||||
* @return The properties for the alias (possibly empty) or null if the alias does not exist.
|
||||
* @return The properties for the alias (possibly empty).
|
||||
*/
|
||||
public Map<String,String> getCollectionAliasProperties(String alias) {
|
||||
// Note: map is already unmodifiable; it can be shared safely
|
||||
|
|
Loading…
Reference in New Issue