src/share/classes/java/lang/System.java

Print this page




 617      * @see        java.lang.SecurityException
 618      * @see        java.lang.SecurityManager#checkPropertiesAccess()
 619      * @see        java.util.Properties
 620      */
 621     public static Properties getProperties() {
 622         SecurityManager sm = getSecurityManager();
 623         if (sm != null) {
 624             sm.checkPropertiesAccess();
 625         }
 626 
 627         return props;
 628     }
 629 
 630     /**
 631      * Returns the system-dependent line separator string.  It always
 632      * returns the same value - the initial value of the {@linkplain
 633      * #getProperty(String) system property} {@code line.separator}.
 634      *
 635      * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
 636      * Windows systems it returns {@code "\r\n"}.
 637      *
 638      * @return the system-dependent line separator string
 639      * @since 1.7
 640      */
 641     public static String lineSeparator() {
 642         return lineSeparator;
 643     }
 644 
 645     private static String lineSeparator;
 646 
 647     /**
 648      * Sets the system properties to the <code>Properties</code>
 649      * argument.
 650      * <p>
 651      * First, if there is a security manager, its
 652      * <code>checkPropertiesAccess</code> method is called with no
 653      * arguments. This may result in a security exception.
 654      * <p>
 655      * The argument becomes the current set of system properties for use
 656      * by the {@link #getProperty(String)} method. If the argument is
 657      * <code>null</code>, then the current set of system properties is
 658      * forgotten.


1203         // way as other threads; we must do it ourselves here.
1204         Thread current = Thread.currentThread();
1205         current.getThreadGroup().add(current);
1206 
1207         // register shared secrets
1208         setJavaLangAccess();
1209 
1210         // Subsystems that are invoked during initialization can invoke
1211         // sun.misc.VM.isBooted() in order to avoid doing things that should
1212         // wait until the application class loader has been set up.
1213         // IMPORTANT: Ensure that this remains the last initialization action!
1214         sun.misc.VM.booted();
1215     }
1216 
1217     private static void setJavaLangAccess() {
1218         // Allow privileged classes outside of java.lang
1219         sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){
1220             public sun.reflect.ConstantPool getConstantPool(Class<?> klass) {
1221                 return klass.getConstantPool();
1222             }
1223             public void setAnnotationType(Class<?> klass, AnnotationType type) {
1224                 klass.setAnnotationType(type);
1225             }
1226             public AnnotationType getAnnotationType(Class<?> klass) {
1227                 return klass.getAnnotationType();



1228             }
1229             public byte[] getRawClassTypeAnnotations(Class<?> klass) {
1230                 return klass.getRawTypeAnnotations();
1231             }
1232             public byte[] getRawExecutableTypeAnnotations(Executable executable) {
1233                 return Class.getExecutableTypeAnnotationBytes(executable);
1234             }
1235             public <E extends Enum<E>>
1236                     E[] getEnumConstantsShared(Class<E> klass) {
1237                 return klass.getEnumConstantsShared();
1238             }
1239             public void blockedOn(Thread t, Interruptible b) {
1240                 t.blockedOn(b);
1241             }
1242             public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
1243                 Shutdown.add(slot, registerShutdownInProgress, hook);
1244             }
1245             public int getStackTraceDepth(Throwable t) {
1246                 return t.getStackTraceDepth();
1247             }


 617      * @see        java.lang.SecurityException
 618      * @see        java.lang.SecurityManager#checkPropertiesAccess()
 619      * @see        java.util.Properties
 620      */
 621     public static Properties getProperties() {
 622         SecurityManager sm = getSecurityManager();
 623         if (sm != null) {
 624             sm.checkPropertiesAccess();
 625         }
 626 
 627         return props;
 628     }
 629 
 630     /**
 631      * Returns the system-dependent line separator string.  It always
 632      * returns the same value - the initial value of the {@linkplain
 633      * #getProperty(String) system property} {@code line.separator}.
 634      *
 635      * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
 636      * Windows systems it returns {@code "\r\n"}.


 637      * @since 1.7
 638      */
 639     public static String lineSeparator() {
 640         return lineSeparator;
 641     }
 642 
 643     private static String lineSeparator;
 644 
 645     /**
 646      * Sets the system properties to the <code>Properties</code>
 647      * argument.
 648      * <p>
 649      * First, if there is a security manager, its
 650      * <code>checkPropertiesAccess</code> method is called with no
 651      * arguments. This may result in a security exception.
 652      * <p>
 653      * The argument becomes the current set of system properties for use
 654      * by the {@link #getProperty(String)} method. If the argument is
 655      * <code>null</code>, then the current set of system properties is
 656      * forgotten.


1201         // way as other threads; we must do it ourselves here.
1202         Thread current = Thread.currentThread();
1203         current.getThreadGroup().add(current);
1204 
1205         // register shared secrets
1206         setJavaLangAccess();
1207 
1208         // Subsystems that are invoked during initialization can invoke
1209         // sun.misc.VM.isBooted() in order to avoid doing things that should
1210         // wait until the application class loader has been set up.
1211         // IMPORTANT: Ensure that this remains the last initialization action!
1212         sun.misc.VM.booted();
1213     }
1214 
1215     private static void setJavaLangAccess() {
1216         // Allow privileged classes outside of java.lang
1217         sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){
1218             public sun.reflect.ConstantPool getConstantPool(Class<?> klass) {
1219                 return klass.getConstantPool();
1220             }
1221             public boolean casAnnotationType(Class<?> klass, AnnotationType oldType, AnnotationType newType) {
1222                 return klass.casAnnotationType(oldType, newType);
1223             }
1224             public AnnotationType getAnnotationType(Class<?> klass) {
1225                 return klass.getAnnotationType();
1226             }
1227             public byte[] getRawClassAnnotations(Class<?> klass) {
1228                 return klass.getRawAnnotations();
1229             }
1230             public byte[] getRawClassTypeAnnotations(Class<?> klass) {
1231                 return klass.getRawTypeAnnotations();
1232             }
1233             public byte[] getRawExecutableTypeAnnotations(Executable executable) {
1234                 return Class.getExecutableTypeAnnotationBytes(executable);
1235             }
1236             public <E extends Enum<E>>
1237                     E[] getEnumConstantsShared(Class<E> klass) {
1238                 return klass.getEnumConstantsShared();
1239             }
1240             public void blockedOn(Thread t, Interruptible b) {
1241                 t.blockedOn(b);
1242             }
1243             public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
1244                 Shutdown.add(slot, registerShutdownInProgress, hook);
1245             }
1246             public int getStackTraceDepth(Throwable t) {
1247                 return t.getStackTraceDepth();
1248             }