epugh commented on code in PR #4893:
URL: https://github.com/apache/solr/pull/4893#discussion_r3971688236


##########
solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java:
##########
@@ -108,24 +120,52 @@ public static String getProperty(String key) {
    * @param defaultValue fallback value if property is not found
    */
   public static String getProperty(String key, String defaultValue) {
-    String value = getPropertyWithCamelCaseFallback(key);
+    String value = resolvePropertyValue(key);
     return value != null ? value : defaultValue;
   }
 
   /**
-   * Get a property from given key or an alias key converted from CamelCase to 
dot separated.
+   * Resolves {@code key} by trying, in order: the key as given; the key 
converted from CamelCase to
+   * dot-separated; and -- if {@code key} is itself a legacy/deprecated 
property name -- the current
+   * property it was replaced by. See {@link #resolveViaDeprecatedMapping} for 
why that last
+   * fallback is needed.
    *
-   * @return property value or value of dot-separated alias key or null if not 
found
+   * @return the resolved value, or null if none of the above are found
    */
-  private static String getPropertyWithCamelCaseFallback(String key) {
+  private static String resolvePropertyValue(String key) {
     String value = System.getProperty(key);
     if (value != null) {
       return value;
-    } else {
-      // Figure out if string is CamelCase and convert to dot separated
-      String altKey = camelCaseToDotSeparated(key);
-      return System.getProperty(altKey);
     }
+    // Figure out if string is CamelCase and convert to dot separated
+    String altKey = camelCaseToDotSeparated(key);
+    value = System.getProperty(altKey);
+    if (value != null) {
+      return value;
+    }
+    return resolveViaDeprecatedMapping(altKey);
+  }
+
+  /**
+   * If {@code dotKey} is a known legacy/deprecated property name, returns the 
value of the current
+   * property it was replaced by (inverted, if the mapping is 
boolean-inverted), or null if that
+   * current property hasn't been set either.
+   *
+   * <p>This matters for config files (e.g. {@code solr.xml}) that still 
contain a {@code
+   * ${legacyName:default}} substitution token from before a property was 
renamed: without this,
+   * setting only the new property name would silently have no effect on that 
token, since nothing
+   * else ever rewrites the token's text. See SOLR-17864.
+   */
+  private static String resolveViaDeprecatedMapping(String dotKey) {
+    DeprecatedMapping mapping = DEPRECATED_MAPPINGS.get(dotKey);
+    if (mapping == null) {
+      return null;
+    }
+    String newValue = System.getProperty(mapping.currentName());

Review Comment:
   okayk this requires moving deprecationLog, so will do in sepeate PR...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to