Buggy code:
public class ReverseJoinHelper { static Cluster currentCluster = Cluster . builder ( ) . addContactPoint ( XmlHandler . getInstance ( ) . getClusterConfig ( ) . getString ( "config.host.localhost" ) ) . withRetryPolicy ( INSTANCE ) . withLoadBalancingPolicy ( new com . datastax . driver . core . policies . TokenAwarePolicy ( new DCAwareRoundRobinPolicy ( ) ) ) . build ( ) ; public static boolean insertStatement ( String joinTable , String keyspace , String joinKeyName , String joinKeyValue , int column , HashMap < String , String > myMap , Stream stream , int counter ) { if ( counter == ( - 1 ) ) { StringBuilder insertQuery = new StringBuilder ( "INSERT<seq2seq4repair_space>INTO<seq2seq4repair_space>" ) . append ( keyspace ) . append ( "." ) . append ( joinTable ) . append ( "<seq2seq4repair_space>(" ) . append ( joinKeyName ) . append ( ",<seq2seq4repair_space>" ) . append ( ( "list_item" + column ) ) . append ( ",<seq2seq4repair_space>stream,<seq2seq4repair_space>counter)<seq2seq4repair_space>VALUES<seq2seq4repair_space>(" ) . append ( joinKeyValue ) . append ( ",<seq2seq4repair_space>?,<seq2seq4repair_space>" ) . append ( Serialize . serializeStream2 ( stream ) ) . append ( ",<seq2seq4repair_space>" ) . append ( ( counter + 1 ) ) . append ( ")<seq2seq4repair_space>IF<seq2seq4repair_space>NOT<seq2seq4repair_space>EXISTS;" ) ; Session session = ReverseJoinHelper . currentCluster . connect ( ) ; PreparedStatement statement = session . prepare ( insertQuery . toString ( ) ) ; BoundStatement boundStatement = new BoundStatement ( statement ) ; Row inserted = session . execute ( boundStatement . bind ( myMap ) ) . one ( ) ; System . out . println ( insertQuery ) ; if ( inserted . getBool ( "[applied]" ) ) return true ; else return false ; } else { StringBuilder updateQuery = new StringBuilder ( "UPDATE<seq2seq4repair_space>" ) ; <START_BUG> updateQuery . append ( keyspace ) . append ( "." ) . append ( joinTable ) . append ( "<seq2seq4repair_space>SET<seq2seq4repair_space>list_item" ) . append ( ( column + 1 ) ) . append ( "=<seq2seq4repair_space>?" ) . append ( ",<seq2seq4repair_space>counter=<seq2seq4repair_space>" ) . append ( ( counter + 1 ) ) . append ( ",<seq2seq4repair_space>stream=<seq2seq4repair_space>" ) . append ( Serialize . serializeStream2 ( stream ) ) . append ( "<seq2seq4repair_space>WHERE<seq2seq4repair_space>" ) . append ( joinKeyName ) . append ( "=<seq2seq4repair_space>" ) . append ( joinKeyValue ) . append ( "<seq2seq4repair_space>IF<seq2seq4repair_space>counter<seq2seq4repair_space>=<seq2seq4repair_space>" ) . append ( counter ) . append ( ";" ) ; <END_BUG> System . out . println ( updateQuery ) ; Row updated ; try { Session session = ReverseJoinHelper . currentCluster . connect ( ) ; PreparedStatement statement = session . prepare ( updateQuery . toString ( ) ) ; BoundStatement boundStatement = new BoundStatement ( statement ) ; updated = session . execute ( boundStatement . bind ( myMap ) ) . one ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return false ; } if ( updated . getBool ( "[applied]" ) ) return true ; else return false ; } } public static void insertStatement ( String joinTable , String keyspace , String joinKeyName , String joinKeyValue , int column , HashMap < String , String > myMap , Stream stream ) { } }

Fix:
updateQuery . append ( keyspace ) . append ( "." ) . append ( joinTable ) . append ( "<seq2seq4repair_space>SET<seq2seq4repair_space>list_item" ) . append ( column ) . append ( "=<seq2seq4repair_space>?" ) . append ( ",<seq2seq4repair_space>counter=<seq2seq4repair_space>" ) . append ( ( counter + 1 ) ) . append ( ",<seq2seq4repair_space>stream=<seq2seq4repair_space>" ) . append ( Serialize . serializeStream2 ( stream ) ) . append ( "<seq2seq4repair_space>WHERE<seq2seq4repair_space>" ) . append ( joinKeyName ) . append ( "=<seq2seq4repair_space>" ) . append ( joinKeyValue ) . append ( "<seq2seq4repair_space>IF<seq2seq4repair_space>counter<seq2seq4repair_space>=<seq2seq4repair_space>" ) . append ( counter ) . append ( ";" ) ;