HistoryService may return invalid varibles for completed task.
Steps to reproduce:
1. Create Task with some variable A
2. Update Task, remove variable A
3. Update Task, set variable A with new value
4. Complete this task
Table ACT_HI_VARINST will store something like
Default SQL loads ALL those variables and puts them into HistoricTaskInstance object (both 101 and 121 loads into queryVariables list). Method HistoricTaskInstance.getTaskLocalVariables collects those variables into map using variable name as a key. So returned map will contains latest putted variable, it may be either variable 101 or variable 121.
As workaround i've added explicit sorting by variable ID to gurantee latest variable entry will be applied.
TestCase to reproduce problem has been attached.
The problem is not always reproduced, change number of iterations (remove variable, set new value) may be required.