`Locale.setDefault` fails in playground with `java...
# kotlin-website
s
Locale.setDefault
fails in playground with
java.security.AccessControlException: Access control exception due to security reasons in web playground
. Is this on purpose?
o
I guess this is just a byproduct of securing the code your enter using a separate JVM that uses a security manager that basically prevents all actions. I cannot see a deliberate choice to disable setting the default locale though. As the JVM is only used once to execute your code, this might be allowed, but I would say it's something so rarely useful that nobody would care...
n
The
java.security.AccessControlException
you're encountering when calling
Locale.setDefault
is intentional. Changing the default locale is a privileged operation, so it's restricted in the Playground for security reasons. If you need to work with a specific locale, you can specify it explicitly in your code without changing the default. For example: https://pl.kotl.in/bN4Yv863L
Copy code
import java.text.NumberFormat
import java.util.Locale

fun main() {
    val locale = Locale("fr", "FR")
    val numberFormat = NumberFormat.getInstance(locale)
    println(numberFormat.format(123456.789))
}
👍 1