Adding constant for line.separator and friends

Martin Buchholz martinrb at
Tue Nov 10 01:09:24 UTC 2009

On Mon, Nov 9, 2009 at 16:34, Martin Buchholz <martinrb at> wrote:
> (In response to Joe, who once asked me for little things to add
> to the core libraries)
> Lots of classes need to use System.getProperty("line.separator").
> Many don't do it right because you need to use
> a doPrivileged block whenever you read a system property.
> Yet it is no secret - you can divine the line separator
> even if you have no trust with the security manager.

Let me clarify somewhat.
The default Policy
defined in src/share/lib/security/java.policy
allows you to access standard system properties
such as line.separator, but...

$ cat &&  java Println

public class Println {
    public static void main(String[] args) {
        Policy.setPolicy(new {
                public boolean implies(ProtectionDomain pd, Permission p) {
                    return false;
        System.setSecurityManager(new SecurityManager());
==> javac -source 1.6 -Xlint:all
==> java -esa -ea Println
Exception in thread "main"
access denied (java.util.PropertyPermission line.separator read)
	at java.lang.SecurityManager.checkPermission(
	at java.lang.SecurityManager.checkPropertyAccess(
	at java.lang.System.getProperty(
	at java.util.Formatter$FormatSpecifier.print(
	at java.util.Formatter.format(
	at Println.main(


Also, only makes available the first char of the system properties
(ensuring that Java will never work on platforms where
file.separator is more than one character,
or is a supplementary character?


More information about the core-libs-dev mailing list