any existing java function that uses the environment variables would have to be modified. i would not change it - openwhisk has a uniform model across all the runtimes and this would start to diverge... i can be convinced but instinct is to leave it alone.
-r On Thu, May 2, 2019 at 10:13 AM Michele Sciabarra <[email protected]> wrote: > 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] >
