This is an automated email from the ASF dual-hosted git repository.
dcapwell pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 3f2e8d1883 NPE in org.apache.cassandra.cql3.Attributes.getTimeToLive
3f2e8d1883 is described below
commit 3f2e8d1883c586bdb9cd7a23076ceaaeefa4bd8c
Author: David Capwell <[email protected]>
AuthorDate: Wed Aug 17 09:47:17 2022 -0700
NPE in org.apache.cassandra.cql3.Attributes.getTimeToLive
patch by David Capwell; reviewed by Caleb Rackliffe for CASSANDRA-17822
---
CHANGES.txt | 1 +
src/java/org/apache/cassandra/cql3/Attributes.java | 5 +++++
.../cassandra/cql3/validation/operations/InsertTest.java | 11 +++++++++++
3 files changed, 17 insertions(+)
diff --git a/CHANGES.txt b/CHANGES.txt
index b8584c3506..9d7d61194b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.2
+ * NPE in org.apache.cassandra.cql3.Attributes.getTimeToLive (CASSANDRA-17822)
* Add guardrail for column size (CASSANDRA-17151)
* When doing a host replacement, we need to check that the node is a live
node before failing with "Cannot replace a live node..." (CASSANDRA-17805)
* Add support to generate a One-Shot heap dump on unhandled exceptions
(CASSANDRA-17795)
diff --git a/src/java/org/apache/cassandra/cql3/Attributes.java
b/src/java/org/apache/cassandra/cql3/Attributes.java
index e841828d79..559882f725 100644
--- a/src/java/org/apache/cassandra/cql3/Attributes.java
+++ b/src/java/org/apache/cassandra/cql3/Attributes.java
@@ -117,6 +117,11 @@ public class Attributes
if (tval == ByteBufferUtil.UNSET_BYTE_BUFFER)
return metadata.params.defaultTimeToLive;
+ // byte[0] and null are the same for Int32Type. UNSET_BYTE_BUFFER is
also byte[0] but we rely on pointer
+ // identity, so need to check this after checking that
+ if (ByteBufferUtil.EMPTY_BYTE_BUFFER.equals(tval))
+ return 0;
+
try
{
Int32Type.instance.validate(tval);
diff --git
a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
index 0f01f3e3d4..0093764b0c 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
@@ -18,6 +18,8 @@
package org.apache.cassandra.cql3.validation.operations;
+import java.nio.ByteBuffer;
+
import org.junit.Assert;
import org.junit.Test;
@@ -29,6 +31,15 @@ import
org.apache.cassandra.exceptions.InvalidRequestException;
public class InsertTest extends CQLTester
{
+ @Test
+ public void testEmptyTTL() throws Throwable
+ {
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, v int)");
+ execute("INSERT INTO %s (k, v) VALUES (0, 0) USING TTL ?", (Object)
null);
+ execute("INSERT INTO %s (k, v) VALUES (1, 1) USING TTL ?",
ByteBuffer.wrap(new byte[0]));
+ assertRows(execute("SELECT k, v, ttl(v) FROM %s"), row(1, 1, null),
row(0, 0, null));
+ }
+
@Test
public void testInsertWithUnset() throws Throwable
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]