Buggy code:
public class CriteriaQueryImpl < T > implements CriteriaQuery < T > , AliasContext { private final MetamodelImpl _model ; private Set < Root < ? > > _roots ; private PredicateImpl _where ; private List < Order > _orders ; private Set < ParameterExpression < ? > > _params ; private List < Selection < ? > > _selections ; private List < Expression < ? > > _groups ; private PredicateImpl _having ; private List < Subquery < ? > > _subqueries ; private Boolean _distinct ; private SubqueryImpl < ? > _delegator ; private final Class < T > _resultClass ; private Class < ? > _runtimeResultClass ; private int aliasCount = 0 ; private static String ALIAS_BASE = "autoAlias" ; private Map < Selection < ? > , Value > _variables = new HashMap < Selection < ? > , Value > ( ) ; private Map < Selection < ? > , Value > _values = new HashMap < Selection < ? > , Value > ( ) ; private Map < Selection < ? > , String > _aliases = null ; private Map < Selection < ? > , Value > _rootVariables = new HashMap < Selection < ? > , Value > ( ) ; private Stack < Context > _contexts = null ; public CriteriaQueryImpl ( MetamodelImpl model , Class < T > resultClass ) { } public CriteriaQueryImpl ( MetamodelImpl model , SubqueryImpl < T > delegator ) { } public void setDelegator ( SubqueryImpl < ? > delegator ) { } public SubqueryImpl < ? > getDelegator ( ) { } public MetamodelImpl getMetamodel ( ) { } public Stack < Context > getContexts ( ) { } public CriteriaQuery < T > distinct ( boolean distinct ) { } public List < Order > getOrderList ( ) { } public Selection < T > getSelection ( ) { } public CriteriaQuery < T > multiselect ( Selection < ? > ... selections ) { } public void registerParameter ( ParameterExpressionImpl < ? > p ) { if ( ( _params ) == null ) _params = new HashSet < ParameterExpression < ? > > ( ) ; if ( _params . add ( p ) ) { <START_BUG> p . setIndex ( _params . size ( ) ) ; <END_BUG> } } public Set < ParameterExpression < ? > > getParameters ( ) { } public List < Selection < ? > > getSelectionList ( ) { } public CriteriaQuery < T > groupBy ( Expression < ? > ... grouping ) { } public CriteriaQuery < T > having ( Expression < Boolean > restriction ) { } public CriteriaQuery < T > having ( Predicate ... restrictions ) { } public CriteriaQuery < T > orderBy ( Order ... o ) { } public CriteriaQuery < T > select ( Selection < ? extends T > selection ) { } public CriteriaQuery < T > select ( Selection < ? > ... selections ) { } public CriteriaQuery < T > where ( Expression < Boolean > restriction ) { } public CriteriaQuery < T > where ( Predicate ... restrictions ) { } public < X > Root < X > from ( EntityType < X > entity ) { } public < X > Root < X > from ( Class < X > cls ) { } public List < Expression < ? > > getGroupList ( ) { } public PredicateImpl getGroupRestriction ( ) { } public PredicateImpl getRestriction ( ) { } public Set < Root < ? > > getRoots ( ) { } public void setRoots ( Set < Root < ? > > roots ) { } public Root < ? > getRoot ( ) { } public boolean isDistinct ( ) { } public Boolean getDistinct ( ) { } public < U > Subquery < U > subquery ( Class < U > type ) { } public LinkedMap getParameterTypes ( ) { } QueryExpressions getQueryExpressions ( ExpressionFactory factory ) { } public void assertRoot ( ) { } public void setContexts ( Stack < Context > contexts ) { } public CriteriaQueryImpl < ? > getAncestor ( ) { } public Map < Selection < ? > , String > getAliases ( ) { } public Context ctx ( ) { } public String getAlias ( Selection < ? > selection ) { } public Value getVariable ( Selection < ? > selection ) { } public Value getValue ( Selection < ? > selection ) { } public void registerVariable ( Selection < ? > node , Value var , Value path ) { } public boolean isRegistered ( Selection < ? > selection ) { } public Value getRegisteredVariable ( Selection < ? > selection ) { } public Value getRegisteredValue ( Selection < ? > selection ) { } public void registerRoot ( Root < ? > root , Value var ) { } public Value getRootVariable ( Root < ? > root ) { } public Value getRegisteredRootVariable ( Root < ? > root ) { } public Class < T > getResultType ( ) { } public Class < ? > getRuntimeResultClass ( ) { } public CriteriaQuery < T > multiselect ( List < Selection < ? > > list ) { } }

Fix:
p . setIndex ( ( ( _params . size ( ) ) - 1 ) ) ;