Skip to content

Commit

Permalink
Use System.getProperty instead of System.getProperties
Browse files Browse the repository at this point in the history
Use System.getProperty to get a specific property instead of first
retrieving all properties with System.getProperties() only to read one
property out of it.

This is more friendly to security managers: instead of requiring the
permission to read and even write all properties
("java.util.PropertyPermission" "*" "read,write"), the policy only needs
to allow reading a specific property, which is much more secure.

Depending on the JVM implementation, System.getProperty can also be more
efficient.
  • Loading branch information
kkofler committed Jan 22, 2018
1 parent 8c1c564 commit 833cf23
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import de.jollyday.configuration.impl.URLConfigurationProvider;
import de.jollyday.util.ClassLoadingUtil;

import java.util.Properties;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -57,8 +56,7 @@ private void addInternalConfigurationProviderProperties(ManagerParameter paramet
}

private void addCustomConfigurationProviderProperties(ManagerParameter parameter) {
Properties systemProps = System.getProperties();
String providersStrList = systemProps.getProperty(ConfigurationProvider.CONFIG_PROVIDERS_PROPERTY);
String providersStrList = System.getProperty(ConfigurationProvider.CONFIG_PROVIDERS_PROPERTY);
if (providersStrList != null) {
String[] providersClassNames = providersStrList.split(",");
for (String providerClassName : providersClassNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class URLConfigurationProvider implements ConfigurationProvider {
@Override
public Properties getProperties() {
Properties properties = new Properties();
Properties systemProps = System.getProperties();
String configURLs = systemProps.getProperty(CONFIG_URLS_PROPERTY);
String configURLs = System.getProperty(CONFIG_URLS_PROPERTY);
if (configURLs != null) {
String[] strConfigURLs = configURLs.split(",");
for (String strURL : strConfigURLs) {
Expand Down

0 comments on commit 833cf23

Please sign in to comment.