Skip to content

Returned maps have wrong key value types. #172

@Audrius-GR

Description

@Audrius-GR

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions