I think this is a bug, but I want to get opinions on this. It appears variables defined by item="" in an iteration are staying in scope for the rest of the query evaluation.
For example:
If I call a select passing in a param map of "bunchIDs" -> a List of Integers, let's say {1,2}, then this XML:
<if test="bunchIDs != null" >
<foreach item="bunchID" collection="bunchIDs" open="AND nd.bunch_id in (" close=")" separator=",">
#{bunchID}
</foreach>
</if>
<if test="bunchID != null" >
AND nd.bunch_id = #{bunchID}
</if>
will produce the where clause
AND nd.bunch_id in (1,2) AND nd.bunch_id=2
I don't think bunchID should be defined anymore when it runs the evaluation <if test="bunchID != null" > happens.