indy256's blog

By indy256, 6 years ago, In English

The following code crashes Java8 on Codeforces:

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

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

Maybe updating Java8 will solve the problem.

 
 
 
 
  • Vote: I like it
  • +27
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it +14 Vote: I do not like it

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.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    I checked that, SecureRandom works fine.

    • »
      »
      »
      6 years ago, # ^ |
      Rev. 8   Vote: I like it +3 Vote: I do not like it

      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

      • »
        »
        »
        »
        6 years ago, # ^ |
        Rev. 4   Vote: I like it 0 Vote: I do not like it

        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.

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

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

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    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.ru/blog/entry/10037)

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it -8 Vote: I do not like it

      We don't have full crush dump or information about protection system. It's all guesswork.

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Who 'we'? And do you mean crAsh dump?

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Yes, crash dump. We — users interested in solving problem :)

»
6 years ago, # |
  Vote: I like it -41 Vote: I do not like it

Typical Java

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    typical troll!

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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