You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cassandra.apache.org by Edward Ribeiro <ed...@gmail.com> on 2009/06/17 02:31:23 UTC
Column assert
Dear developers,
I saw the following piece of the code in the Column class:
Column(String name, byte[] value, long timestamp, boolean isDeleted)
{
assert name != null;
assert value != null;
[ ... ]
}
Well, the assert is a debug facility and it should not be used in
production code, because it only throws an exception when the code is
run with the -ea switch. There are other classes that follow the same
behaviour in Cassandra code base. If this is being used in place of a
null checking "if" statement then I would be glad to submit a couple
of patches to fix that.
By the way, I saw that Cassandra project currently uses the very good
google collections library. Therefore, the code can become even more
succint like:
import static com.google.common.base.Preconditions.*;
[...]
Column(String name, byte[] value, long timestamp, boolean isDeleted)
{
assertNotNull(name,"Column name cannot be null!");
assertNotNull(value, "Byte array cannot be null!");
[...]
}
Best regards,
Edward
Re: Column assert
Posted by Edward Ribeiro <ed...@gmail.com>.
That's alright.
Edward
On Tue, Jun 16, 2009 at 9:45 PM, Jonathan Ellis<jb...@gmail.com> wrote:
> checking user input is done with explicit if statements; verifying
> internal assumptions is done with asserts. Column is not a
> user-facing class (that would be column_t).
>
> -Jonathan
>
> On Tue, Jun 16, 2009 at 7:31 PM, Edward Ribeiro<ed...@gmail.com> wrote:
>> Dear developers,
>>
>> I saw the following piece of the code in the Column class:
>>
>> Column(String name, byte[] value, long timestamp, boolean isDeleted)
>> {
>> assert name != null;
>> assert value != null;
>> [ ... ]
>> }
>>
>> Well, the assert is a debug facility and it should not be used in
>> production code, because it only throws an exception when the code is
>> run with the -ea switch. There are other classes that follow the same
>> behaviour in Cassandra code base. If this is being used in place of a
>> null checking "if" statement then I would be glad to submit a couple
>> of patches to fix that.
>>
>> By the way, I saw that Cassandra project currently uses the very good
>> google collections library. Therefore, the code can become even more
>> succint like:
>>
>> import static com.google.common.base.Preconditions.*;
>>
>> [...]
>>
>> Column(String name, byte[] value, long timestamp, boolean isDeleted)
>> {
>> assertNotNull(name,"Column name cannot be null!");
>> assertNotNull(value, "Byte array cannot be null!");
>> [...]
>> }
>>
>> Best regards,
>> Edward
>>
>
Re: Column assert
Posted by Jonathan Ellis <jb...@gmail.com>.
checking user input is done with explicit if statements; verifying
internal assumptions is done with asserts. Column is not a
user-facing class (that would be column_t).
-Jonathan
On Tue, Jun 16, 2009 at 7:31 PM, Edward Ribeiro<ed...@gmail.com> wrote:
> Dear developers,
>
> I saw the following piece of the code in the Column class:
>
> Column(String name, byte[] value, long timestamp, boolean isDeleted)
> {
> assert name != null;
> assert value != null;
> [ ... ]
> }
>
> Well, the assert is a debug facility and it should not be used in
> production code, because it only throws an exception when the code is
> run with the -ea switch. There are other classes that follow the same
> behaviour in Cassandra code base. If this is being used in place of a
> null checking "if" statement then I would be glad to submit a couple
> of patches to fix that.
>
> By the way, I saw that Cassandra project currently uses the very good
> google collections library. Therefore, the code can become even more
> succint like:
>
> import static com.google.common.base.Preconditions.*;
>
> [...]
>
> Column(String name, byte[] value, long timestamp, boolean isDeleted)
> {
> assertNotNull(name,"Column name cannot be null!");
> assertNotNull(value, "Byte array cannot be null!");
> [...]
> }
>
> Best regards,
> Edward
>