incubator-cassandra-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ohad Shacham <>
Subject Atomically adding a column to columns_
Date Sun, 26 Sep 2010 09:38:37 GMT

We are building a tool for detecting non atomic usages of concurrent

We analyzed your code using our tool and found the following behavior:

Function addColumn at class SuperColumn tries to atomically add a column to
the concurrent collection “columns_” using the following code:

IColumn oldColumn = columns_.putIfAbsent(name, column);
if (oldColumn != null)

IColumn reconciledColumn = reconciler.reconcile((Column)column,

while (!columns_.replace(name, oldColumn, reconciledColumn))  {

oldColumn = columns_.get(name);
reconciledColumn = reconciler.reconcile((Column)column, (Column)oldColumn);



This code can throw NullPointerException at function reconcile if there is a
columns_.remove(…) operation on the same key, by a different thread, between
the previous executed “columns_.replace(…)” and “columns_.get(…)”

Could you please let me know whether you consider this as a bug?

Another very similar scenario can occur at function “addColumn” of class
“ColumnFamily” where the program can throw NullPointerException while
checking the while loop condition.

A possible way of modifying the code for atomically adding a column to
“columns_” can be as follows:

for (;;) {

IColumn  oldColumn = columns_.get(name);

if (oldColumn == null) {

if (columns_.putIfAbsent(name, column) == null)


} else {

IColumn reconciledColumn = reconciler.reconcile((Column)column,

if (columns_.replace(name, oldColumn, reconciledColumn))






  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message