Codeforces / polygon-issue-tracking

polygon-issue-tracking
16 stars 2 forks source link

java.security.AccessControlException when trying to set up fast output #419

Closed elizarov closed 4 years ago

elizarov commented 4 years ago

On JVM (Java & Kotlin) the default System.out is configured with auto-flush on each line which makes it very slow on problems with many lines in the output. To work around it, while still being able to use standard output functions (like Kotlin's println), we can reconfigure output without autoflush like this:

System.setOut(PrintStream(FileOutputStream(FileDescriptor.out), false))

However, running this code results in the following exception:

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "readFileDescriptor")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkRead(SecurityManager.java:864)
    at java.io.FileInputStream.<init>(FileInputStream.java:171)

Once the above is fixed fixed, there will be the following exception on an attempt to do System.setOut:

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setIO")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.System.checkIO(System.java:253)

Here is an example of submission using this approach for fast output: https://codeforces.com/contest/1322/submission/72937574

Expected behavior: it should work.

MikeMirzayanov commented 4 years ago

Done, the submission got Time limit exceeded on test 72.