+ 9
[Expert] Kotlin AccessControlException in files and network
I've seen multiple cases recently, when some Kotlin codes that used to work previously, are now failing, on the web code playground they freeze, in the SL app they just finish with the message 'An error occurred'. In these codes we try to do file operations with java.io or network operations with java.net and after debugging, the source of error is java.security.AccessControlException These codes work flawlessly in an IDE, in fact they used to work on SL too! Any help to figure out the source of the problem, and potential solution or workaround, would be appreciated. Some references: https://code.sololearn.com/codry9wz88cA/?ref=app https://code.sololearn.com/cBljm28Qf9H7/?ref=app https://code.sololearn.com/c0VtBwW9GJxi/?ref=app
3 odpowiedzi
+ 10
If I run this code on the official playground it'll give same security exception.
But why this works in Intellij though?
https://code.sololearn.com/cxT8B6rv1zeN/?ref=app
Also one thing I noticed, I can't use <readAllBytes> in official and SL playground. Only <readBytes>
But Intellij allows both!
Any reason why <readAllBytes> gives unresolved reference here?
+ 5
So far what I found:
Same code does not work on official Kotlin playground either, failing with same error.
https://pl.kotl.in/1gmzoFRGY
From https://developer.android.com/reference/kotlin/java/security/AccessControlException -
"This exception is thrown by the AccessController to indicate that a requested access (to a critical system resource such as the file system or the network) is denied.
The reason to deny access can vary. For example, the requested permission might be of an incorrect type, contain an invalid value, or request access that is not allowed according to the security policy. Such information should be given whenever possible at the time the exception is thrown."
More on security manager:
https://www.baeldung.com/java-security-manager
+ 5
Minho 🇰🇷 probably because of the JDK version used by the Kotlin compiler in SL playground, I suspect it is using Java 8
https://stackoverflow.com/questions/54269211/cant-resolve-method-readallbytes