diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 7d10471d952..0573b135928 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -610,37 +610,44 @@ public class Configuration implements Iterable>, * deprecated key, the value of the deprecated key is set as the value for * the provided property name. * + * @param deprecations deprecation context * @param name the property name * @return the first property in the list of properties mapping * the name or the name itself. */ private String[] handleDeprecation(DeprecationContext deprecations, - String name) { + String name) { if (null != name) { name = name.trim(); } - ArrayList names = new ArrayList(); - if (isDeprecated(name)) { - DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name); - warnOnceIfDeprecated(deprecations, name); - for (String newKey : keyInfo.newKeys) { - if(newKey != null) { - names.add(newKey); + // Initialize the return value with requested name + String[] names = new String[]{name}; + // Deprecated keys are logged once and an updated names are returned + DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name); + if (keyInfo != null) { + if (!keyInfo.getAndSetAccessed()) { + logDeprecation(keyInfo.getWarningMessage(name)); + } + // Override return value for deprecated keys + names = keyInfo.newKeys; + } + // If there are no overlay values we can return early + Properties overlay = getOverlay(); + if (overlay.isEmpty()) { + return names; + } + // Update properties and overlays with reverse lookup values + for (String n : names) { + String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n); + if (deprecatedKey != null && !overlay.containsKey(n)) { + String deprecatedValue = overlay.getProperty(deprecatedKey); + if (deprecatedValue != null) { + getProps().setProperty(n, deprecatedValue); + overlay.setProperty(n, deprecatedValue); } } } - if(names.size() == 0) { - names.add(name); - } - for(String n : names) { - String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n); - if (deprecatedKey != null && !getOverlay().containsKey(n) && - getOverlay().containsKey(deprecatedKey)) { - getProps().setProperty(n, getOverlay().getProperty(deprecatedKey)); - getOverlay().setProperty(n, getOverlay().getProperty(deprecatedKey)); - } - } - return names.toArray(new String[names.size()]); + return names; } private void handleDeprecation() { @@ -1175,11 +1182,8 @@ public class Configuration implements Iterable>, } } - private void warnOnceIfDeprecated(DeprecationContext deprecations, String name) { - DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name); - if (keyInfo != null && !keyInfo.getAndSetAccessed()) { - LOG_DEPRECATION.info(keyInfo.getWarningMessage(name)); - } + private void logDeprecation(String message) { + LOG_DEPRECATION.info(message); } /**