Describe the bug
(Describe the problem clearly and concisely.)
ThreadLocalRandom.current().nextLong() always generates the same numbers on each startup. This only happens when I run a native image.
Expected behavior
(Describe the expected behavior clearly and concisely.)
ThreadLocalRandom.current().nextLong() generates different numbers on each startup.
Actual behavior
(Describe the actual behavior clearly and concisely.)
ThreadLocalRandom.current().nextLong() generates same numbers on each startup.
To Reproduce
Steps to reproduce the behavior:
package org.acme;
import io.quarkus.runtime.StartupEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.enterprise.event.Observes;
import javax.ws.rs.core.Application;
import java.util.concurrent.ThreadLocalRandom;
public class ExampleApp extends Application {
private static final Logger _logger = LoggerFactory.getLogger(ExampleApp.class);
public void onInit(@Observes StartupEvent evt) {
for (int i = 0; i < 10; i++) {
_logger.info("Random: {}", ThreadLocalRandom.current().nextLong());
}
}
}
Configuration
quarkus.package.type=native
quarkus.native.container-build=true
quarkus.native.container-runtime=docker
Screenshots
(If applicable, add screenshots to help explain your problem.)

Environment (please complete the following information):
uname -a or ver: Linux nb-xxx 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linuxjava -version: openjdk version "11.0.8" 2020-07-14mvnw --version or gradlew --version): Gradle 6.4.1Additional context
(Add any other context about the problem here.)
Seems to be related to https://github.com/oracle/graal/issues/1610 and the fix should be available in GraalVM 20.2.0
/cc @galderz wondering if we would want that one backported to Mandrel?
Bad news: I just tested in 20.2.0 and that doesn't seem to be fixed for ThreadLocalRandoms or Math.random :disappointed:
Bad news: I just tested in 20.2.0 and that doesn't seem to be fixed for
ThreadLocalRandoms orMath.random馃槥
It looked surprising that a year old fix didn't make it to 20.2 which was recently released. So I had a look and it appears that this feature isn't enabled by default in Graal VM. I am not sure if that was intentional. I have opened https://github.com/oracle/graal/pull/2790 with a proposed fix.
https://github.com/oracle/graal/issues/1610 is included in both Mandrel 20.1 and 20.2. Hope the improvement fix gets included too.
Just dropping another issue for you to be aware of: https://github.com/oracle/graal/pull/2993