Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInteger may cause hanging tests in jdk17 #78

Closed
jk-idealo opened this issue Jun 13, 2022 · 3 comments · Fixed by #80
Closed

BigInteger may cause hanging tests in jdk17 #78

jk-idealo opened this issue Jun 13, 2022 · 3 comments · Fixed by #80
Labels

Comments

@jk-idealo
Copy link
Collaborator

jk-idealo commented Jun 13, 2022

The following test will sometimes hang and run forever without errors or exceptions in java 17:

    @Test
    void xxx() {
        var result = fixture().create(BigInteger.class);

        assertThat(result).isInstanceOf(BigInteger.class);
    }
@jk-idealo jk-idealo added the bug label Jun 13, 2022
@jk-idealo jk-idealo changed the title BigInteger may cause hanging tests BigInteger may cause hanging tests in jdk17 Jun 13, 2022
@akutschera
Copy link
Collaborator

That's an interesting one.
Because of JDK17 we cannot use reflection.
Then we use a fallback that tries to use a random constructor. These will fail in most cases (we may get lucky if we randomly choose new Random(int numBits, Random rnd) and randomly call it with a positive numBits value).
If the constructor fails we fallback to the factory methods. There we have two:

  • valueOf(long val) which will always succeed and
  • probablePrime(int bitLength, Random rnd) which will succeed when bitLength is not negative
    When bitLength is a large number (e.g. 5_000) the probablePrime call takes a long time to finish (>7s on my machine, compared to 300ms for 1_000 bits).

I suggest that we add BigInteger to the special specimens that need extra knowledge for fixturing, like URL.

@Nylle
Copy link
Owner

Nylle commented Jun 15, 2022

I suggest that we add BigInteger to the special specimens that need extra knowledge for fixturing, like URL.

I agree. 👍

@akutschera akutschera linked a pull request Jun 16, 2022 that will close this issue
@akutschera
Copy link
Collaborator

Creating a BigInteger with the maximum number of possible bits takes quite long (>1000ms) each time. Therefore I propose to limit a fixtured BigInteger to max. 1024 bit. If someone needs more, we can still add a configuration parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants