cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Jirsa (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CASSANDRA-9077) NPE
Date Tue, 31 Mar 2015 05:47:54 GMT

    [ https://issues.apache.org/jira/browse/CASSANDRA-9077?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14388054#comment-14388054
] 

Jeff Jirsa edited comment on CASSANDRA-9077 at 3/31/15 5:47 AM:
----------------------------------------------------------------

The underlying problem is that o.a.c.db.composites.AbstractCellNameType.CQL3RowOfSparse getMultiCellColumn()
can return null (if collection==null), which happens if/when you delete the list. 

A very similar NPE would be thrown if you tried to update to set a list element by index once
the list was deleted:

{noformat}
cqlsh:test2> update t set l[0] = '1' where id='user';
ServerError: <ErrorMessage code=0000 [Server error] message="java.lang.NullPointerException">
{noformat}

{noformat}
ERROR [SharedPool-Worker-1] 2015-03-30 22:22:32,682 QueryMessage.java:132 - Unexpected error
during query
java.lang.NullPointerException: null
	at org.apache.cassandra.cql3.Lists$SetterByIndex.execute(Lists.java:345) ~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:111)
~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:58)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.getMutations(ModificationStatement.java:643)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.executeWithoutCondition(ModificationStatement.java:475)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:461)
~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:234) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:261) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:246) ~[main/:na]
	at org.apache.cassandra.transport.messages.QueryMessage.execute(QueryMessage.java:119) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:475) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:371) ~[main/:na]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.access$700(AbstractChannelHandlerContext.java:32)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext$8.run(AbstractChannelHandlerContext.java:324)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_25]
	at org.apache.cassandra.concurrent.AbstractTracingAwareExecutorService$FutureTask.run(AbstractTracingAwareExecutorService.java:164)
~[main/:na]
	at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:105) ~[main/:na]
	at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
ERROR [SharedPool-Worker-1] 2015-03-30 22:22:32,683 ErrorMessage.java:329 - Unexpected exception
during request
java.lang.NullPointerException: null
	at org.apache.cassandra.cql3.Lists$SetterByIndex.execute(Lists.java:345) ~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:111)
~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:58)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.getMutations(ModificationStatement.java:643)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.executeWithoutCondition(ModificationStatement.java:475)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:461)
~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:234) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:261) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:246) ~[main/:na]
	at org.apache.cassandra.transport.messages.QueryMessage.execute(QueryMessage.java:119) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:475) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:371) ~[main/:na]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.access$700(AbstractChannelHandlerContext.java:32)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext$8.run(AbstractChannelHandlerContext.java:324)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_25]
	at org.apache.cassandra.concurrent.AbstractTracingAwareExecutorService$FutureTask.run(AbstractTracingAwareExecutorService.java:164)
~[main/:na]
	at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:105) ~[main/:na]
	at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
{noformat}

There are two ways to fix this - could either 

1) Check for null in Lists.java, and throw a new error trying to delete an element from an
empty list (or similarly, try to add an element at an index of an empty list), 
{noformat}
cqlsh:test2> INSERT INTO t (id, l, s) VALUES ('user', ['1'], {'1'}); DELETE l FROM t WHERE
id ='user'; DELETE l[0] FROM t WHERE id = 'user';
InvalidRequest: code=2200 [Invalid query] message="Attempt to delete from an empty list"
cqlsh:test2> update t set l[0] = '1' where id='user';                                 
                                                                                         
                                                                      
InvalidRequest: code=2200 [Invalid query] message="Attempt to set an element on a null list"
cqlsh:test2> 
{noformat}

2) Make it return an actual empty list instead of null, in which case the existing bounds
checking works as intended: 

{noformat}
cqlsh:test2> INSERT INTO t (id, l, s) VALUES ('user', ['1'], {'1'}); DELETE l FROM t WHERE
id ='user'; DELETE l[0] FROM t WHERE id = 'user';                                        
                                                                  
InvalidRequest: code=2200 [Invalid query] message="List index 0 out of bound, list has size
0"
cqlsh:test2> update t set l[0] = '1' where id='user';                                 
                                                                                         
                                                                      
InvalidRequest: code=2200 [Invalid query] message="List index 0 out of bound, list has size
0"
cqlsh:test2> 
{noformat}

Both patches attached. Leaving it to a reviewer to decide which is the right approach (perhaps
both?)



was (Author: jjirsa):
The underlying problem is that o.a.c.db.composites.AbstractCellNameType.CQL3RowOfSparse getMultiCellColumn()
can return null (if collection==null), which happens if/when you delete the list. 

A very similar NPE would be thrown if you tried to update to set a list element by index once
the list was deleted:

{noformat}
cqlsh:test2> update t set l[0] = '1' where id='user';
ServerError: <ErrorMessage code=0000 [Server error] message="java.lang.NullPointerException">
{noformat}

{noformat}
ERROR [SharedPool-Worker-1] 2015-03-30 22:22:32,682 QueryMessage.java:132 - Unexpected error
during query
java.lang.NullPointerException: null
	at org.apache.cassandra.cql3.Lists$SetterByIndex.execute(Lists.java:345) ~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:111)
~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:58)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.getMutations(ModificationStatement.java:643)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.executeWithoutCondition(ModificationStatement.java:475)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:461)
~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:234) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:261) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:246) ~[main/:na]
	at org.apache.cassandra.transport.messages.QueryMessage.execute(QueryMessage.java:119) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:475) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:371) ~[main/:na]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.access$700(AbstractChannelHandlerContext.java:32)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext$8.run(AbstractChannelHandlerContext.java:324)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_25]
	at org.apache.cassandra.concurrent.AbstractTracingAwareExecutorService$FutureTask.run(AbstractTracingAwareExecutorService.java:164)
~[main/:na]
	at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:105) ~[main/:na]
	at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
ERROR [SharedPool-Worker-1] 2015-03-30 22:22:32,683 ErrorMessage.java:329 - Unexpected exception
during request
java.lang.NullPointerException: null
	at org.apache.cassandra.cql3.Lists$SetterByIndex.execute(Lists.java:345) ~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:111)
~[main/:na]
	at org.apache.cassandra.cql3.statements.UpdateStatement.addUpdateForKey(UpdateStatement.java:58)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.getMutations(ModificationStatement.java:643)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.executeWithoutCondition(ModificationStatement.java:475)
~[main/:na]
	at org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:461)
~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:234) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:261) ~[main/:na]
	at org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:246) ~[main/:na]
	at org.apache.cassandra.transport.messages.QueryMessage.execute(QueryMessage.java:119) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:475) ~[main/:na]
	at org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:371) ~[main/:na]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.access$700(AbstractChannelHandlerContext.java:32)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext$8.run(AbstractChannelHandlerContext.java:324)
~[netty-all-4.0.23.Final.jar:4.0.23.Final]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_25]
	at org.apache.cassandra.concurrent.AbstractTracingAwareExecutorService$FutureTask.run(AbstractTracingAwareExecutorService.java:164)
~[main/:na]
	at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:105) ~[main/:na]
	at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
{noformat}

There are two ways to fix this - could either 

1) Check for null in Lists.java, and throw a new error trying to delete an element from an
empty list (or similarly, try to add an element at an index of an empty list), 
{noformat}
cqlsh:test2> INSERT INTO t (id, l, s) VALUES ('user', ['1'], {'1'}); DELETE l FROM t WHERE
id ='user'; DELETE l[0] FROM t WHERE id = 'user';InvalidRequest: code=2200 [Invalid query]
message="Attempt to delete from an empty list"
cqlsh:test2> update t set l[0] = '1' where id='user';                                 
                                                                                         
                                                                      InvalidRequest: code=2200
[Invalid query] message="Attempt to set an element on a null list"
cqlsh:test2> 
{noformat}

2) Make it return an actual empty list instead of null, in which case the existing bounds
checking works as intended: 

{noformat}
cqlsh:test2> INSERT INTO t (id, l, s) VALUES ('user', ['1'], {'1'}); DELETE l FROM t WHERE
id ='user'; DELETE l[0] FROM t WHERE id = 'user';                                        
                                                                  InvalidRequest: code=2200
[Invalid query] message="List index 0 out of bound, list has size 0"
cqlsh:test2> update t set l[0] = '1' where id='user';                                 
                                                                                         
                                                                      InvalidRequest: code=2200
[Invalid query] message="List index 0 out of bound, list has size 0"
cqlsh:test2> 
{noformat}

Both patches attached. Leaving it to a reviewer to decide which is the right approach (perhaps
both?)


> NPE
> ---
>
>                 Key: CASSANDRA-9077
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-9077
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>            Reporter: dan jatnieks
>            Priority: Minor
>         Attachments: 9077-stacktrace.log
>
>
> I am seeing an NPE on the latest 2.1 branch with this sequence of deletes from a list
- first delete the entire list, then attempt to delete one element.
> I expected to see {{List index 0 out of bound, list has size 0}} but instead got an NPE.
> {noformat}
> ./bin/cqlsh
> Connected to Test Cluster at 127.0.0.1:9042.
> [cqlsh 5.0.1 | Cassandra 2.1.3-SNAPSHOT | CQL spec 3.2.0 | Native protocol v3]
> Use HELP for help.
> cqlsh> use frozen_collections ;
> cqlsh:frozen_collections> DROP TABLE IF EXISTS t;
> cqlsh:frozen_collections> CREATE TABLE t (id text PRIMARY KEY, l list<text>,
s set<text>);
> cqlsh:frozen_collections> INSERT INTO t (id, l, s) VALUES ('user', ['1'], {'1'});
> cqlsh:frozen_collections>
> cqlsh:frozen_collections> DELETE l FROM t WHERE id ='user';
> cqlsh:frozen_collections> //INSERT INTO t (id, l) VALUES ('user', ['1']);
> cqlsh:frozen_collections> DELETE l[0] FROM t WHERE id = 'user';
> ServerError: <ErrorMessage code=0000 [Server error] message="java.lang.NullPointerException">
> cqlsh:frozen_collections>
> cqlsh:frozen_collections> DELETE s FROM t WHERE id ='user';
> cqlsh:frozen_collections> DELETE s['1'] FROM t WHERE id = 'user';
> {noformat}
> It appears the {{DELETE emails...}} directly followed by {{DELETE emails[0]...}} is the
offending sequence. Either one alone works fine, as does adding an intervening insert/update.
> The same sequence performed on a Set rather than List works (as shown above).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message