thibaultmeyer / cuid-java

Collision-resistant ids optimized for horizontal scaling and performance
MIT License
41 stars 2 forks source link

ArrayIndexOutOfBoundsException on createEntropy method #8

Closed dawidkarczewski closed 3 months ago

dawidkarczewski commented 4 months ago

Describe the bug After many iterations of creating CUIDv2 by method CUID.randomCUID2() an exception is thrown:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -8 out of bounds for length 10
    at io.github.thibaultmeyer.cuid.CUID$CUIDv2.createEntropy(CUID.java:271)
    at io.github.thibaultmeyer.cuid.CUID.randomCUID2(CUID.java:71)
    at io.github.thibaultmeyer.cuid.CUID.randomCUID2(CUID.java:52)
    at org.example.Main.main(Main.java:8)

To Reproduce Steps to reproduce the behavior:

Just generate CUID in the loop. It takes time (in my case over 1h), for example

import io.github.thibaultmeyer.cuid.CUID;

public class Main {
    public static void main(String[] args) {
        while (true) {
            CUID.randomCUID2();
        }
    }
}

Expected behavior An exception should never be thrown

Additional context Java 11

czarekm commented 3 months ago

Hi @thibaultmeyer . I've created PR to fix it => https://github.com/thibaultmeyer/cuid-java/pull/9

thibaultmeyer commented 3 months ago

Resolved by #9 Version 2.0.3 released