diff --git cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java index 63668bc..8f3aa58 100644 --- cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java +++ cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java @@ -376,21 +376,24 @@ public void testprocessInitFiles() throws Exception { } - private static void setEnv(String key, String value) throws Exception { - Class[] classes = Collections.class.getDeclaredClasses(); - Map env = (Map) System.getenv(); - for (Class cl : classes) { - if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) { - Field field = cl.getDeclaredField("m"); - field.setAccessible(true); - Object obj = field.get(env); - Map map = (Map) obj; - if (value == null) { - map.remove(key); - } else { - map.put(key, value); - } - } + private void setEnv(String key, String value) throws Exception { + Class processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); + Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment"); + theEnvironmentField.setAccessible(true); + Map env = (Map) theEnvironmentField.get(null); + if (value == null) { + env.remove(key); + } else { + env.put(key, value); + } + + Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment"); + theCaseInsensitiveEnvironmentField.setAccessible(true); + Map cienv = (Map) theCaseInsensitiveEnvironmentField.get(null); + if (value == null) { + cienv.remove(key); + } else { + cienv.put(key, value); } }