-
Notifications
You must be signed in to change notification settings - Fork 222
Description
Hi,
Thanks for the great library, but I've got a question/issue.
Let's say I am storing a Map<Int, Int> in a bin.
When packing, that nicely realizes that the ints are small values, and stores them as shorts server side.
Great.
Now when I read the map back out of the bin, due to this:
aerospike-client-java/client/src/com/aerospike/client/util/Unpacker.java
Lines 297 to 300 in d65f8f8
| case 0xcd: { // unsigned 16 bit integer | |
| int val = Buffer.bytesToShort(buffer, offset); | |
| offset += 2; | |
| return getLong(val); |
I always end up reading a Map<Long, Long>.
Now what is worse, if I do something like this:
mapWritten.keys().forEach { key ->
doSomething(mapReadBack[key])
}
I always end up getting nulls, because the int key I just wrote, does not match anything in the returned map as the map now has longs and any keep lookup fails equality due to type mismatch.
Obviously this should be a type error but JVM erasure hides it, and developers end up sinking quite some time into debugging this 😞
What's worse is that this might lead to runtime errors in applications, that expect to do integer arithmetic etc with the values they got back 😞
I assume this is not intentional?
Or if it is, where is this documented, because it's definitely a "gotcha" that caught me out.
Best wishes.