Class ConfigUtil


  • public final class ConfigUtil
    extends java.lang.Object
    Configuration utilities.

    This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ConfigUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T defaultIfNull​(T value, T defaultValue)
      Returns defaultValue if value is null, otherwise value.
      static java.lang.String getString​(java.lang.String key, java.lang.String defaultValue)
      Return the system property or environment variable for the key.
      static java.lang.String normalizeEnvironmentVariableKey​(java.lang.String key)
      Normalize an environment variable key by converting to lower case and replacing "_" with ".".
      static java.lang.String normalizePropertyKey​(java.lang.String key)
      Normalize a property key by converting to lower case and replacing "-" with ".".
      static java.util.Properties safeSystemProperties()
      Returns a copy of system properties which is safe to iterate over.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConfigUtil

        private ConfigUtil()
    • Method Detail

      • safeSystemProperties

        public static java.util.Properties safeSystemProperties()
        Returns a copy of system properties which is safe to iterate over.

        In java 8 and android environments, iterating through system properties may trigger ConcurrentModificationException. This method ensures callers can iterate safely without risk of exception. See https://github.com/open-telemetry/opentelemetry-java/issues/6732 for details.

      • getString

        public static java.lang.String getString​(java.lang.String key,
                                                 java.lang.String defaultValue)
        Return the system property or environment variable for the key.

        Normalize the key using normalizePropertyKey(String). Match to system property keys also normalized with normalizePropertyKey(String). Match to environment variable keys normalized with normalizeEnvironmentVariableKey(String). System properties take priority over environment variables.

        Parameters:
        key - the property key
        Returns:
        the system property if not null, or the environment variable if not null, or defaultValue
      • normalizeEnvironmentVariableKey

        public static java.lang.String normalizeEnvironmentVariableKey​(java.lang.String key)
        Normalize an environment variable key by converting to lower case and replacing "_" with ".".
      • normalizePropertyKey

        public static java.lang.String normalizePropertyKey​(java.lang.String key)
        Normalize a property key by converting to lower case and replacing "-" with ".".
      • defaultIfNull

        public static <T> T defaultIfNull​(@Nullable
                                          T value,
                                          T defaultValue)
        Returns defaultValue if value is null, otherwise value. This is an internal method.