Buggy code:
public class CollectionParam extends Const implements Parameter { private static final Localizer _loc = Localizer . forPackage ( CollectionParam . class ) ; private final Object _key ; private Class _type = null ; private int _idx = - 1 ; private boolean _container = false ; public CollectionParam ( Object key , Class type ) { } public Object getParameterKey ( ) { } public Class getType ( ) { } public void setImplicitType ( Class type ) { } public int getIndex ( ) { } public void setIndex ( int idx ) { } public Object getValue ( Object [ ] params ) { } public Object getValue ( ExpContext ctx , ExpState state ) { } public Object getSQLValue ( Select sel , ExpContext ctx , ExpState state ) { } public ExpState initialize ( Select sel , ExpContext ctx , int flags ) { } public static class ParamExpState extends ConstExpState { public int size = 0 ; public Object [ ] sqlValue = null ; public int [ ] otherLength ; public ClassMapping [ ] mapping = null ; public Discriminator [ ] disc = null ; public Object [ ] discValue = null ; ParamExpState ( Object params ) { } } public void calculateValue ( Select sel , ExpContext ctx , ExpState state , Val other , ExpState otherState ) { super . calculateValue ( sel , ctx , state , other , otherState ) ; CollectionParam . ParamExpState pstate = ( ( CollectionParam . ParamExpState ) ( state ) ) ; Object value = getValue ( ctx . params ) ; if ( ! ( value instanceof Collection ) ) throw new IllegalArgumentException ( CollectionParam . _loc . get ( "not-collection-parm" , _key ) . toString ( ) ) ; if ( ( ( Collection ) ( value ) ) . isEmpty ( ) ) throw new IllegalArgumentException ( CollectionParam . _loc . get ( "empty-collection-parm" , _key ) . toString ( ) ) ; Iterator itr = ( ( Collection ) ( value ) ) . iterator ( ) ; for ( int i = 0 ; ( i < ( pstate . size ) ) && ( itr . hasNext ( ) ) ; i ++ ) { Object val = itr . next ( ) ; if ( ( other != null ) && ( ! ( _container ) ) ) { pstate . sqlValue [ i ] = other . toDataStoreValue ( sel , ctx , otherState , val ) ; pstate . otherLength [ i ] = other . length ( sel , ctx , otherState ) ; if ( other instanceof Type ) { pstate . mapping [ i ] = ctx . store . getConfiguration ( ) . getMappingRepositoryInstance ( ) . getMapping ( ( ( Class ) ( val ) ) , ctx . store . getContext ( ) . getClassLoader ( ) , true ) ; pstate . disc [ i ] = pstate . mapping [ i ] . getDiscriminator ( ) ; <START_BUG> pstate . discValue [ i ] = ( ( pstate . disc ) != null ) ? pstate . disc [ i ] . getValue ( ) : null ; <END_BUG> } } else if ( ImplHelper . isManageable ( val ) ) { ClassMapping mapping = ctx . store . getConfiguration ( ) . getMappingRepositoryInstance ( ) . getMapping ( val . getClass ( ) , ctx . store . getContext ( ) . getClassLoader ( ) , true ) ; pstate . sqlValue [ i ] = mapping . toDataStoreValue ( val , mapping . getPrimaryKeyColumns ( ) , ctx . store ) ; pstate . otherLength [ i ] = mapping . getPrimaryKeyColumns ( ) . length ; } else pstate . sqlValue [ i ] = val ; } } public void appendTo ( Select sel , ExpContext ctx , ExpState state , SQLBuffer sql , int index ) { } }

Fix:
pstate . discValue [ i ] = ( ( pstate . disc [ i ] ) != null ) ? pstate . disc [ i ] . getValue ( ) : null ;