NPE when trying to remove a map entry

Description

The only way to remove an entry from a map is:

QueryBuilder.put('myMap',myKey,null);

However, this leads to NPE at https://github.com/datastax/java-driver/blob/2.0/driver-core/src/main/java/com/datastax/driver/core/BoundStatement.java?source=c#L176

Easy fix

Environment

Cassandra 2.0.3

Pull Requests

None

Activity

Show:
DOAN DuyHai
February 25, 2014, 4:01 PM

What I suspect you did was trying to bind a map with null values inside (may a putAll() but definitively not a put())

Exactly that. I was naively thinking that with 1 operation, I can perform insertion and deletion on a map:

but is seems not possible because as you said collection literal cannot have nulls.

In this case I'll need 2 steps to perform insertion + deletion

You can close the JIRA, it's definitely not a bug

Sylvain Lebresne
February 25, 2014, 3:06 PM

The only way to remove an entry from a map is:

That's not true, you can use a DELETE (it's the only way, "with an UPDATE").

However, this leads to NPE at https://github.com/datastax/java-driver/blob/2.0/driver-core/src/main/java/com/datastax/driver/core/BoundStatement.java?source=c#L176

You may want to produce a more complete example because:

  1. I just have successfully tested using QueryBuilder.put('myMap',myKey,null) without any problem

  2. you link to BoundStatement which suggests prepared statement are used, but even then I'm able to prepare a QueryBuilder.put('myMap',?,?) and bound the value to null without problem

  3. the line you highlight in BoundStatement should not concerned by a QueryBuilder.put as far as I can tell, which is why point 2 above works.

What I suspect you did was trying to bind a map with null values inside (may a putAll() but definitively not a put()). In which case, this is not supported by Cassandra currently (collections literal cannot have nulls) so returning a NPE is not entirely inappropriate.

Not a Problem

Assignee

Unassigned

Reporter

DOAN DuyHai

Affects versions