Community,

Let's make a long story short:

In the openwhisk runtime for java, when you activate an action, you have to 
pass some informatins. Most notably those:

---
{
  "namespace": String,
  "action_name": String,
  "api_host": String,
  "api_key": String,
  "activation_id": String,
  "transaction_id": String,
  "deadline": Number
}
---

Now, the common way in all the programming languages is to set environement 
variables:

so action_name is passed as __OW_ACTION_NAME and so on.

This is easy in every programming language except java. In Java "you should not 
change environment variables". Because the concept of environemnt variables is 
actually to use "system properties". Generally all the environment variables 
are used to set system properties, read only.

In che java8 runtime however the environment variables has been set. Following 
this stack overlflow  "horrible and unacceptable' (my opinion) hack

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

Note this "vomit causing" (still my opinion) thing:

        Field field = cl.getDeclaredField("m");
        field.setAccessible(true);

Yep, you hack an in-memory undocumented hash map marked read only with 
reflection to say "no, I want to write in it anyway" and then proceed your 
surgery.

I very very very very unwillingly applied this hack in the actionloop runtime 
for java 8 for the sake of keeping compatibility and pass all the existing 
tests. 

For java 11 however, this hack also requires you mark the runtime as using 
"unsafe code"

I thing this thing now it is a bit ... too much. So we should instead change 
the way we pass the values and use system properties instead. 

Yes, user code for Java11 need  to be changed. No more System.getenv(...) but 
System.getProperties.

Your thoughts?


-- 
  Michele Sciabarra
  mich...@sciabarra.com

Reply via email to