Блог пользователя indy256

Автор indy256, 10 лет назад, По-английски

The following code crashes Java8 on Codeforces:

public class Main {
    public static void main(String[] args) {
        java.math.BigInteger.valueOf(7).nextProbablePrime();
    }
}

http://codeforces.com/contest/427/submission/6539822

Maybe updating Java8 will solve the problem.

  • Проголосовать: нравится
  • +27
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

It's well known issue, that nextProbablePrime() use low level access to OS for rand seed and code of "probematic frame" sayed, that crash was in native code and it may be caused by security policy of OS.

  • »
    »
    10 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    I checked that, SecureRandom works fine.

    • »
      »
      »
      10 лет назад, # ^ |
      Rev. 8   Проголосовать: нравится +3 Проголосовать: не нравится

      I have the same version of JRE at workstation ( but i have client version, not server ) and no problems. As I can see native calls in ThreadLocalRandom.current() are the reason of crush. It used in internals of java.math.BigInteger#passesMillerRabin

      • »
        »
        »
        »
        10 лет назад, # ^ |
        Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

        Actually I meant that nextProbablePrime uses SecureRandom. On Codeforces servers SecureRandom doesn't crash Java, but nextProbablePrime does. Or what did you mean?

        UPD. Seen your UPD. I thought that it only uses SecureRandom, but I didn't know Java well enough, I see. :)

        Was SecureRandom replaced by ThreadLocalRandom in Java 8?

        UPD2. In Java 7 and 6, ThreadLocalRandom.current() doesn't crash.

        • »
          »
          »
          »
          »
          10 лет назад, # ^ |
            Проголосовать: нравится +3 Проголосовать: не нравится

          I don't know in detail how Codeforces protect they java-run sandboxes :)

  • »
    »
    10 лет назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    Mike wrote that OS' low-level rand seed is problematic and they are using java -Djava.security.egd=file:filename to set seed for SecureRandom. (Russian: http://codeforces.com/blog/entry/10037)

»
10 лет назад, # |
  Проголосовать: нравится -41 Проголосовать: не нравится

Typical Java

  • »
    »
    10 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    typical troll!

    • »
      »
      »
      10 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      yes, but still, he has +72 of contribution (at the time of writing), which is almost the same of yours (+73 at the time of writing). Contribution is not supposed to be a measure of "anti-trollness" also? Amazing CodeForces.

      • »
        »
        »
        »
        10 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        yeah, i noticed that he has a lot of upvotes in Russian interface. i don't know Russian very well, so unfortunately i can't judge him there.
        however, he is nothing but a troll in English! :D