diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java index 4f2c96e367..a899a0344f 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java @@ -168,7 +168,7 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac */ public void initialize() { if (logger.isInfoEnabled()) { - logger.info("Initializing ExecutorService " + (this.beanName != null ? " '" + this.beanName + "'" : "")); + logger.info("Initializing ExecutorService" + (this.beanName != null ? " '" + this.beanName + "'" : "")); } if (!this.threadNamePrefixSet && this.beanName != null) { setThreadNamePrefix(this.beanName + "-"); diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index 19130e9ec1..3ad07215d3 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -380,12 +380,9 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { @Override @SuppressWarnings({"unchecked", "rawtypes"}) - public Map getSystemEnvironment() { - if (suppressGetenvAccess()) { - return Collections.emptyMap(); - } + public Map getSystemProperties() { try { - return (Map) System.getenv(); + return (Map) System.getProperties(); } catch (AccessControlException ex) { return (Map) new ReadOnlySystemAttributesMap() { @@ -393,11 +390,11 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { @Nullable protected String getSystemAttribute(String attributeName) { try { - return System.getenv(attributeName); + return System.getProperty(attributeName); } catch (AccessControlException ex) { if (logger.isInfoEnabled()) { - logger.info("Caught AccessControlException when accessing system environment variable '" + + logger.info("Caught AccessControlException when accessing system property '" + attributeName + "'; its value will be returned [null]. Reason: " + ex.getMessage()); } return null; @@ -407,26 +404,14 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } } - /** - * Determine whether to suppress {@link System#getenv()}/{@link System#getenv(String)} - * access for the purposes of {@link #getSystemEnvironment()}. - *

If this method returns {@code true}, an empty dummy Map will be used instead - * of the regular system environment Map, never even trying to call {@code getenv} - * and therefore avoiding security manager warnings (if any). - *

The default implementation checks for the "spring.getenv.ignore" system property, - * returning {@code true} if its value equals "true" in any case. - * @see #IGNORE_GETENV_PROPERTY_NAME - * @see SpringProperties#getFlag - */ - protected boolean suppressGetenvAccess() { - return SpringProperties.getFlag(IGNORE_GETENV_PROPERTY_NAME); - } - @Override @SuppressWarnings({"unchecked", "rawtypes"}) - public Map getSystemProperties() { + public Map getSystemEnvironment() { + if (suppressGetenvAccess()) { + return Collections.emptyMap(); + } try { - return (Map) System.getProperties(); + return (Map) System.getenv(); } catch (AccessControlException ex) { return (Map) new ReadOnlySystemAttributesMap() { @@ -434,11 +419,11 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { @Nullable protected String getSystemAttribute(String attributeName) { try { - return System.getProperty(attributeName); + return System.getenv(attributeName); } catch (AccessControlException ex) { if (logger.isInfoEnabled()) { - logger.info("Caught AccessControlException when accessing system property '" + + logger.info("Caught AccessControlException when accessing system environment variable '" + attributeName + "'; its value will be returned [null]. Reason: " + ex.getMessage()); } return null; @@ -448,6 +433,21 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } } + /** + * Determine whether to suppress {@link System#getenv()}/{@link System#getenv(String)} + * access for the purposes of {@link #getSystemEnvironment()}. + *

If this method returns {@code true}, an empty dummy Map will be used instead + * of the regular system environment Map, never even trying to call {@code getenv} + * and therefore avoiding security manager warnings (if any). + *

The default implementation checks for the "spring.getenv.ignore" system property, + * returning {@code true} if its value equals "true" in any case. + * @see #IGNORE_GETENV_PROPERTY_NAME + * @see SpringProperties#getFlag + */ + protected boolean suppressGetenvAccess() { + return SpringProperties.getFlag(IGNORE_GETENV_PROPERTY_NAME); + } + @Override public void merge(ConfigurableEnvironment parent) { for (PropertySource ps : parent.getPropertySources()) { diff --git a/spring-core/src/main/java/org/springframework/core/env/ConfigurableEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/ConfigurableEnvironment.java index d2b20052ec..1d875f2cd0 100644 --- a/spring-core/src/main/java/org/springframework/core/env/ConfigurableEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/ConfigurableEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ import java.util.Map; *

  * ConfigurableEnvironment environment = new StandardEnvironment();
  * MutablePropertySources propertySources = environment.getPropertySources();
- * Map myMap = new HashMap();
+ * Map<String, String> myMap = new HashMap<>();
  * myMap.put("xyz", "myValue");
  * propertySources.addFirst(new MapPropertySource("MY_MAP", myMap));
  * 
@@ -78,26 +78,26 @@ public interface ConfigurableEnvironment extends Environment, ConfigurableProper *

Any existing active profiles will be replaced with the given arguments; call * with zero arguments to clear the current set of active profiles. Use * {@link #addActiveProfile} to add a profile while preserving the existing set. + * @throws IllegalArgumentException if any profile is null, empty or whitespace-only * @see #addActiveProfile * @see #setDefaultProfiles * @see org.springframework.context.annotation.Profile * @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME - * @throws IllegalArgumentException if any profile is null, empty or whitespace-only */ void setActiveProfiles(String... profiles); /** * Add a profile to the current set of active profiles. - * @see #setActiveProfiles * @throws IllegalArgumentException if the profile is null, empty or whitespace-only + * @see #setActiveProfiles */ void addActiveProfile(String profile); /** * Specify the set of profiles to be made active by default if no other profiles * are explicitly made active through {@link #setActiveProfiles}. - * @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME * @throws IllegalArgumentException if any profile is null, empty or whitespace-only + * @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME */ void setDefaultProfiles(String... profiles); @@ -119,34 +119,34 @@ public interface ConfigurableEnvironment extends Environment, ConfigurableProper MutablePropertySources getPropertySources(); /** - * Return the value of {@link System#getenv()} if allowed by the current + * Return the value of {@link System#getProperties()} if allowed by the current * {@link SecurityManager}, otherwise return a map implementation that will attempt - * to access individual keys using calls to {@link System#getenv(String)}. - *

Note that most {@link Environment} implementations will include this system - * environment map as a default {@link PropertySource} to be searched. Therefore, it - * is recommended that this method not be used directly unless bypassing other - * property sources is expressly intended. + * to access individual keys using calls to {@link System#getProperty(String)}. + *

Note that most {@code Environment} implementations will include this system + * properties map as a default {@link PropertySource} to be searched. Therefore, it is + * recommended that this method not be used directly unless bypassing other property + * sources is expressly intended. *

Calls to {@link Map#get(Object)} on the Map returned will never throw * {@link IllegalAccessException}; in cases where the SecurityManager forbids access * to a property, {@code null} will be returned and an INFO-level log message will be * issued noting the exception. */ - Map getSystemEnvironment(); + Map getSystemProperties(); /** - * Return the value of {@link System#getProperties()} if allowed by the current + * Return the value of {@link System#getenv()} if allowed by the current * {@link SecurityManager}, otherwise return a map implementation that will attempt - * to access individual keys using calls to {@link System#getProperty(String)}. - *

Note that most {@code Environment} implementations will include this system - * properties map as a default {@link PropertySource} to be searched. Therefore, it is - * recommended that this method not be used directly unless bypassing other property - * sources is expressly intended. + * to access individual keys using calls to {@link System#getenv(String)}. + *

Note that most {@link Environment} implementations will include this system + * environment map as a default {@link PropertySource} to be searched. Therefore, it + * is recommended that this method not be used directly unless bypassing other + * property sources is expressly intended. *

Calls to {@link Map#get(Object)} on the Map returned will never throw * {@link IllegalAccessException}; in cases where the SecurityManager forbids access * to a property, {@code null} will be returned and an INFO-level log message will be * issued noting the exception. */ - Map getSystemProperties(); + Map getSystemEnvironment(); /** * Append the given parent environment's active profiles, default profiles and