Optimize SystemEnvPropertySource when possible
Update SystemEnvironmentPropertySource to attempt optimized Map lookups first, and only fall-back to the defensive SecurityManager safe-mode if these fail. Issue: SPR-12224
This commit is contained in:
@@ -16,15 +16,15 @@
|
||||
|
||||
package org.springframework.core.env;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SystemEnvironmentPropertySource}.
|
||||
*
|
||||
@@ -101,4 +101,18 @@ public class SystemEnvironmentPropertySourceTests {
|
||||
assertThat(ps.getProperty("a.key"), equalTo((Object)"a_value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSecurityConstraints() throws Exception {
|
||||
envMap = new HashMap<String, Object>() {
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
ps = new SystemEnvironmentPropertySource("sysEnv", envMap);
|
||||
envMap.put("A_KEY", "a_value");
|
||||
assertThat(ps.containsProperty("A_KEY"), equalTo(true));
|
||||
assertThat(ps.getProperty("A_KEY"), equalTo((Object)"a_value"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user