Hello all,

I am in the process of writing a new ActionLoop based runtime for Java, I have 
a prototype and it is 10times faster so it is worth the effort.

I am trying to make it backward compatible with the existing.
In the process I found the way the current runtime sets environment variables.
Since it is well known it is not possible in Java (everyone uses 
System.properties as a replacement), this is what the current runtime does to 
change them:

---
private static void augmentEnv(Map<String, String> newEnv) {
        try {
            for (Class cl : Collections.class.getDeclaredClasses()) {
                if 
("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                    Field field = cl.getDeclaredField("m");
                    field.setAccessible(true);
                    Object obj = field.get(System.getenv());
                    Map<String, String> map = (Map<String, String>) obj;
                    map.putAll(newEnv);
                }
            }
        } catch (Exception e) {}
    }
---


Basically, since the Env is an unmodifiable map, looks like it HACKS it with 
reflection, it finding a private field, forcing it to be accessible and 
modifying it.

An hack from StackOverflow: 
https://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java

My stomach cannot stand the disgust of this horror. What will happen if in the 
new runtime I use  System properties to pass environment variables instead (as 
it is the common practice in Java)? 

Will huge codebases break and large companies will be sued for daring to break 
backward compatibility? 


-- 
  Michele Sciabarra
  [email protected]

Reply via email to