aerospike / aerospike-client-java

Aerospike Java Client Library
Other
236 stars 212 forks source link

[Bug] client throws ArrayIndexOutOfBoundsException when key is too long #131

Closed justinplus closed 5 years ago

justinplus commented 5 years ago

Hi Aerospike team,

I discovered that if the key is String, and its size is too long, Aerospike client throws ArrayIndexOutOfBoundsException. Is it better to throw other more meaningful exception instead?

ps: I'm using version 4.1.7.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8192
    at com.aerospike.client.command.Buffer.stringToUtf8(Buffer.java:195)
    at com.aerospike.client.Value$StringValue.write(Value.java:574)
    at com.aerospike.client.Key.computeDigest(Key.java:315)
    at com.aerospike.client.Key.<init>(Key.java:94)
    at TryAerospike.main(TryAerospike.java:25)

Thank you, Justin

BrianNichols commented 5 years ago

The key's maximum size is documented in javadocs for all key constructors. The existing exception in combination with the documentation is sufficient. From the javadocs:

The key is converted to bytes to compute the digest. The key's byte size is limited to the current thread's buffer size (min 8KB). To store keys > 8KB, do one of the following:

Set once:

ThreadLocalData.DefaultBufferSize = maxKeySize + maxSetNameSize + 1;

Or for every key:

int len = key.length() + setName.length() + 1;
if (len > ThreadLocalData.getBuffer().length))
    ThreadLocalData.resizeBuffer(len);
Aloren commented 5 years ago

what's the problem with adding validation of input parameters? this is standard for any public api.