Fix failing system environment tests on Windows
Issue: SPR-8245 git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4390 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
fe50d070f9
commit
a38c086e62
|
|
@ -291,6 +291,8 @@ public class EnvironmentTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Map<String, String> getModifiableSystemEnvironment() {
|
private static Map<String, String> getModifiableSystemEnvironment() {
|
||||||
|
|
||||||
|
// for os x / linux
|
||||||
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
||||||
Map<String, String> env = System.getenv();
|
Map<String, String> env = System.getenv();
|
||||||
for (Class<?> cl : classes) {
|
for (Class<?> cl : classes) {
|
||||||
|
|
@ -299,12 +301,45 @@ public class EnvironmentTests {
|
||||||
Field field = cl.getDeclaredField("m");
|
Field field = cl.getDeclaredField("m");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object obj = field.get(env);
|
Object obj = field.get(env);
|
||||||
return (Map<String, String>) obj;
|
if (obj != null) {
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for windows
|
||||||
|
Class<?> processEnvironmentClass;
|
||||||
|
try {
|
||||||
|
processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
||||||
|
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
||||||
|
Object obj = theCaseInsensitiveEnvironmentField.get(null);
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// do nothing
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
||||||
|
theEnvironmentField.setAccessible(true);
|
||||||
|
Object obj = theEnvironmentField.get(null);
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// do nothing
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue