/** * Records and returns the specified value. Hence an expression can be replaced * with record(expression) without impacting evaluation of the expression. */ public Object record(int index, Object value) { realizeNas(index + 1, null); values.set(index, value); boolean foundThisCallOnStack = false; while (!startedRecordings.isEmpty()){ final Integer indexFromStack = startedRecordings.pop(); if (indexFromStack==index){ foundThisCallOnStack = true; break; } } if (!foundThisCallOnStack){ throw new IllegalStateException("Did not find call #"+index+" on stack. Invalid call of record method?"); } return value; }