fxlae / typeid-java

A Java implementation of TypeID (Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs).
Apache License 2.0
22 stars 4 forks source link

Fix bug for when the first char is non-ascii char #5

Closed aleris closed 5 months ago

aleris commented 5 months ago

Crashes with: Index 258 out of bounds for length 256 java.lang.ArrayIndexOutOfBoundsException: Index 258 out of bounds for length 256

This adds a check for bigger SUFFIX_LOOKUP.length indexes for the first char.

fxlae commented 5 months ago

Thanks, good catch!

Now that I'm looking at that line, I'm wondering why I didn't just check the first character directly against the range of valid characters (if (firstChar < '0' || firstChar > '7') // -> error) and avoid the lookup altogether. The second part of the check ((SUFFIX_LOOKUP[firstChar] >>> 3) & 0x3) > 0) isn't that great either and could then be removed.

What do you think?

aleris commented 5 months ago

you are right :) updated

fxlae commented 5 months ago

Thanks again :) I will push a new release later today.