[ 
https://issues.apache.org/jira/browse/CASSANDRA-21743?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dipankar Achinta reassigned CASSANDRA-21743:
--------------------------------------------

    Assignee: Dipankar Achinta

> SELECT JSON of an empty boolean value fails with NullPointerException
> ---------------------------------------------------------------------
>
>                 Key: CASSANDRA-21743
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-21743
>             Project: Apache Cassandra
>          Issue Type: Bug
>          Components: CQL/Semantics
>            Reporter: Nadav Har'El
>            Assignee: Dipankar Achinta
>            Priority: Normal
>             Fix For: 5.0.x, 6.x, 7.x
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> A boolean column can hold an empty (zero-length) value, which is different 
> from null. Reading it normally works (the driver returns null), but SELECT 
> JSON fails with a server error:
> {code:sql}
> CREATE TABLE ks.t (p int PRIMARY KEY, v boolean);
> INSERT INTO ks.t (p, v) VALUES (1, blobAsBoolean(0x));
> SELECT v FROM ks.t;         -- works
> SELECT JSON v FROM ks.t;    -- fails
> {code}
> The SELECT JSON fails with:
> {noformat}
> Server error: java.lang.NullPointerException: Cannot invoke 
> "java.lang.Boolean.toString()" because the return value of 
> "org.apache.cassandra.serializers.TypeSerializer.deserialize(java.nio.ByteBuffer)"
>  is null
> {noformat}
> For other types this already works: SELECT JSON of an empty int, bigint, 
> float, double, decimal, varint, timestamp, uuid, timeuuid, inet or text value 
> returns an empty string, "". Most of these cases are covered by 
> cql3/EmptyValuesTest, which was added with the fix for CASSANDRA-15896 (the 
> same NullPointerException for an empty UUID; the commit message says 
> "CASSANDRA-1589", apparently a typo). But EmptyValuesTest has no test for 
> boolean (nor for varint or tinyint), which is probably how this case was 
> missed.
> The cause is that BooleanType.toJSONString() calls 
> getSerializer().deserialize(buffer).toString(), and deserializing an empty 
> buffer returns null. Other types handle this case - e.g., 
> Int32Type.toJSONString() returns "\"\"" for an empty value.
> Reproduced on Cassandra 5.0.9 and 6.0-alpha2.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to