1

Today I'm learning about IO in java. When I look at lineSeparator string in BufferedWriter class I saw the statement

lineSeparator = java.security.AccessController.doPrivileged(
        new sun.security.action.GetPropertyAction("line.separator"));

which initialize the lineSeparator string. But I don't find

sun.security.action.GetPropertyAction(String args)

class in java source. So I get confused how java uses this class which is not in java source. So tell me:

  • where this classes is defined and how JVM call this class ?
  • Can we call this class in our own program ?
Sachin Kumar
  • 781
  • 1
  • 9
  • 28

2 Answers2

2

Java has this class you can see from here, but you shouldn't use sun(now oracle package at your code) source here the reason of why shouldn't use it. And the meaining of

java.security.AccessController.doPrivileged(
        new sun.security.action.GetPropertyAction("line.separator"));

The code that uses doPrivileged says "Give me the value of the property, if the current class (where this line of code is in) is allowed to read it."

here there is another discussion to understand it better

EDIT : It is under your JDK Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar you can learn rt.jar details

Community
  • 1
  • 1
erhun
  • 3,549
  • 2
  • 35
  • 44
0

It's 2020 and this still happens. One quick way to resolve the problem is use installed JDK instead of JRE coming from eclipse installation. GoTo Windows>Preferences>Java>Installed JREs and add your installed JDK and use it as default. enter image description here