JavaSnippet in 2.12: Serious Change in handling static variables!

Dear Knimers,

first of all thanks for the great product - it's a pleasure to work with!

But with the new version 2.12 I encountered a serious change (and big problem for my WFs) concerning the 'JavaSnippet' node. It seems to me that in 2.12 static variables are not re-initialized anymore  when re-executing a node.

Example: I have a WF consisting of 'TableCreator->JavaSnippet' where the data in 'TableCreator' conists of 3 lines (1 column: column1) with values 'A', 'B', 'C'. The JavaSnippet contains the following code:

// Your custom variables;
static String txt = "Start:";

// Enter your code here:
txt += c_column1;	
out_text = txt;

where 'out_text' points to  FlowVariable 'text' (string)!

The first execution of this WF produces 'text='Start:ABC' in both versions ( 2.11.3, 2.12) but re-executing the 'JavaSnippet' (reset->execute) or the whole WF produces ''text='Start:ABCABC' in 2.12 while 'text='Start:ABC' is returned in 2.11.3. This seems to me that the initialization of static variables is now done once PER LIFETIME and not once PER EXECUTION of a node -  as it was done in 2.11.3.

This has serious impacts on my workflow, because I used static variables when there was the need to collect information over rows easily in one step (node execution).


Erich Gstrein


As a workaround, you can check the row index and when it is 0, you can reset your static variables.

Yes, this might work - after having identified all JavaSnippet nodes using static variables in all of my WFs:(

At the moment I have no problem staying with 2.11.3 - but for mid-term considerations it is important to know if this  new behaviour is seen as a bug...


I guess this problem was introduced by "Enh 5509: Java Snippet should cache compiled code". Since static variables are intialized only once when the class is loaded and we now cache the compiled snippet as long as the source code doesn't change this leads to your observed behaviour. This should be fixed of course, we will look into it.