Buggy code:
public class GPURangedRecursiveCall < R extends Number , R2 , T > extends GPUGenericKernel implements RecursiveTemplateSource < R , R2 , T > { public static final int NUM_WORKERS = 128 ; private static final int RECURSION_LIMIT = 512 ; public T output ; public Recursive2DStrategy < R , R2 , T > strategy ; PList < R > starts ; PList < R > ends ; PList < R2 > tops ; PList < R2 > bottoms ; PList < Boolean > results ; Stack < Quad < R , R2 > > stack = new Stack < Quad < R , R2 > > ( ) ; int maxWorkUnits = 0 ; boolean isDone ; boolean is2D = true ; protected CLBuffer < ? > sbuffer ; protected CLBuffer < ? > pbuffer ; protected CLBuffer < ? > ebuffer ; protected CLBuffer < ? > tbuffer = null ; protected CLBuffer < ? > bbuffer = null ; protected CLBuffer < ? > abuffer ; protected CLBuffer < Integer > rbuffer ; private RecursiveCodeGen < R , R2 , T > gen ; public GPURangedRecursiveCall ( Recursive2DStrategy < R , R2 , T > recursiveStrategy ) { } @ Override public void prepareBuffers ( CLContext ctx ) { } public int prepareReadBuffers ( R st , R end , R2 top , R2 bottom , int splits ) { } public void copyRangeBuffers ( CLContext ctx ) { } public int extendFirst ( int size ) { } @ SuppressWarnings ( "unchecked" ) @ Override public void execute ( CLContext ctx , CLQueue q ) { CLEvent [ ] eventsArr = new CLEvent [ 1 ] ; int [ ] rs ; boolean reuseControlBuffers = false ; int workUnits = prepareReadBuffers ( strategy . getStart ( ) , strategy . getEnd ( ) , strategy . getTop ( ) , strategy . getBottom ( ) , GPURangedRecursiveCall . NUM_WORKERS ) ; copyRangeBuffers ( ctx ) ; pbuffer = BufferHelper . createOutputBufferFor ( ctx , strategy . getStart ( ) . getClass ( ) . getSimpleName ( ) , GPURangedRecursiveCall . NUM_WORKERS ) ; rbuffer = ( ( CLBuffer < Integer > ) ( BufferHelper . createOutputBufferFor ( ctx , "Integer" , GPURangedRecursiveCall . NUM_WORKERS ) ) ) ; abuffer = BufferHelper . createOutputBufferFor ( ctx , strategy . getSeed ( ) . getClass ( ) . getSimpleName ( ) , GPURangedRecursiveCall . NUM_WORKERS ) ; int global_counter = 0 ; do { synchronized ( kernel ) { if ( is2D ) { } else { int reuse_steps = ( reuseControlBuffers ) ? 1 : 0 ; kernel . setArgs ( sbuffer , ebuffer , abuffer , rbuffer , starts . size ( ) , ( global_counter ++ ) , reuse_steps , pbuffer ) ; } setExtraDataArgs ( 7 , kernel ) ; eventsArr [ 0 ] = kernel . enqueueNDRange ( q , new int [ ] { GPURangedRecursiveCall . NUM_WORKERS } , eventsArr ) ; } reuseControlBuffers = true ; rs = rbuffer . read ( q , eventsArr [ 0 ] ) . getInts ( ) ; for ( int i = 0 ; i < workUnits ; i ++ ) { if ( ( rs [ i ] ) == 2 ) { reuseControlBuffers = false ; break ; } } if ( reuseControlBuffers ) { if ( ( System . getenv ( "DEBUG" ) ) != null ) { R stepXprobe = ( ( R ) ( BufferHelper . extractElementFromBuffer ( pbuffer , q , eventsArr [ 0 ] , strategy . getStart ( ) . getClass ( ) . getSimpleName ( ) ) ) ) ; System . out . println ( ( ( ( "Repeating<seq2seq4repair_space>with<seq2seq4repair_space>more<seq2seq4repair_space>granularity:<seq2seq4repair_space>" + stepXprobe ) + "<seq2seq4repair_space>with<seq2seq4repair_space>control<seq2seq4repair_space>" ) + ( rs [ 0 ] ) ) ) ; } continue ; } filterAndSplitFirst ( workUnits , rs ) ; copyRangeBuffers ( ctx ) ; workUnits = starts . size ( ) ; } while ( ! ( isDone ) ) ; rbuffer . release ( ) ; <START_BUG> PList < T > accs = ( ( PList < T > ) ( BufferHelper . extractFromBuffer ( abuffer , q , eventsArr [ 0 ] , strategy . getSeed ( ) . getClass ( ) . getSimpleName ( ) , workUnits ) ) ) ; <END_BUG> output = strategy . getSeed ( ) ; for ( T acc : accs ) { output = strategy . combine ( output , acc ) ; } abuffer . release ( ) ; } private void filterAndSplitFirst ( int workUnits , int [ ] rs ) { } @ Override public void retrieveResults ( CLContext ctx , CLQueue q ) { } @ Override public String getSource ( ) { } @ Override public String getKernelName ( ) { } public T getOutput ( ) { } @ SuppressWarnings ( "unchecked" ) public void createEmptyLists ( ) { } class Pair { public R s ; public R e ; public Pair ( R s , R e ) { } } @ Override public String getRType ( ) { } @ Override public String getR2Type ( ) { } @ Override public String getTType ( ) { } @ Override public Recursive2DStrategy < R , R2 , T > getRecursiveStrategy ( ) { } @ Override public int getRecursionLimit ( ) { } }

Fix:
PList < T > accs = ( ( PList < T > ) ( BufferHelper . extractFromBuffer ( abuffer , q , eventsArr [ 0 ] , strategy . getSeed ( ) . getClass ( ) . getSimpleName ( ) , GPURangedRecursiveCall . NUM_WORKERS ) ) ) ;