AnsweredAssumed Answered

HistoricProcessInstanceQuery statefull invocations

Question asked by deg on Jan 30, 2015
Latest reply on Feb 16, 2015 by deg
This remark is related to  http://forums.activiti.org/en/viewtopic.php?f=3&t=593

I was trying to reuse a created processInstanceQuery on activiti 5.16.3.  I assumed that finished and unfinished are each other opposites, just like deleted and notDeleted seem to be be each other opposites. So I expected that the code below

final HistoricProcessInstanceQuery processQuery = createQuery(procesDefinitionKey);
for (int i = 0; i < 3; i++) {
     System.out.println("Check[" + i + "] There are " + processQuery.finished().list().size() + " finished");
     System.out.println("Check[" + i + "] There are " + processQuery.unfinished().list().size() + " unfinished");
}


would print something like this:


Check[0] There are 2 finished
Check[0] There are 0 unfinished
Check[1] There are 2 finished
Check[1] There are 0 unfinished
Check[2] There are 2 finished
Check[2] There are 0 unfinished


instead it prints this:


Check[0] There are 2 finished
Check[0] There are 0 unfinished
Check[1] There are 0 finished
Check[1] There are 0 unfinished
Check[2] There are 0 finished
Check[2] There are 0 unfinished


Looking into the source of HistoricProcessInstanceQueryImpl (Long live open source :-) ) i see that there are four booleans

protected boolean finished = false;
protected boolean unfinished = false;
protected boolean deleted = false;
protected boolean notDeleted = false;


were i  would expect two. This allows <b>a query to be finished and unfinished, deleted and not deleted at the same time!</b> This results in strange and very unintuitive behavior.

Outcomes