src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 47359 e1a6c0168741
equal deleted inserted replaced
47311:ff631a3cadbc 47312:d4f959806fe9
    31 import java.util.Iterator;
    31 import java.util.Iterator;
    32 import java.util.Properties;
    32 import java.util.Properties;
    33 import java.util.ServiceConfigurationError;
    33 import java.util.ServiceConfigurationError;
    34 import java.util.ServiceLoader;
    34 import java.util.ServiceLoader;
    35 import java.util.function.Supplier;
    35 import java.util.function.Supplier;
       
    36 import jdk.xml.internal.SecuritySupport;
    36 
    37 
    37 /**
    38 /**
    38  * <p>Implements pluggable streams.</p>
    39  * <p>Implements pluggable streams.</p>
    39  *
    40  *
    40  * <p>This class is duplicated for each JAXP subpackage so keep it in
    41  * <p>This class is duplicated for each JAXP subpackage so keep it in
    60      * Flag indicating if properties from java.home/conf/jaxp.properties
    61      * Flag indicating if properties from java.home/conf/jaxp.properties
    61      * have been cached.
    62      * have been cached.
    62      */
    63      */
    63     private static volatile boolean firstTime = true;
    64     private static volatile boolean firstTime = true;
    64 
    65 
    65     /**
       
    66      * Security support class use to check access control before
       
    67      * getting certain system resources.
       
    68      */
       
    69     final private static SecuritySupport ss = new SecuritySupport();
       
    70 
       
    71     // Define system property "jaxp.debug" to get output
    66     // Define system property "jaxp.debug" to get output
    72     static {
    67     static {
    73         // Use try/catch block to support applets, which throws
    68         // Use try/catch block to support applets, which throws
    74         // SecurityException out of this code.
    69         // SecurityException out of this code.
    75         try {
    70         try {
    76             String val = ss.getSystemProperty("jaxp.debug");
    71             String val = SecuritySupport.getSystemProperty("jaxp.debug");
    77             // Allow simply setting the prop to turn on debug
    72             // Allow simply setting the prop to turn on debug
    78             debug = val != null && !"false".equals(val);
    73             debug = val != null && !"false".equals(val);
    79         }
    74         }
    80         catch (SecurityException se) {
    75         catch (SecurityException se) {
    81             debug = false;
    76             debug = false;
   105         try {
   100         try {
   106             if (cl == null) {
   101             if (cl == null) {
   107                 if (useBSClsLoader) {
   102                 if (useBSClsLoader) {
   108                     return Class.forName(className, false, FactoryFinder.class.getClassLoader());
   103                     return Class.forName(className, false, FactoryFinder.class.getClassLoader());
   109                 } else {
   104                 } else {
   110                     cl = ss.getContextClassLoader();
   105                     cl = SecuritySupport.getContextClassLoader();
   111                     if (cl == null) {
   106                     if (cl == null) {
   112                         throw new ClassNotFoundException();
   107                         throw new ClassNotFoundException();
   113                     }
   108                     }
   114                     else {
   109                     else {
   115                         return Class.forName(className, false, cl);
   110                         return Class.forName(className, false, cl);
   254         // Use the system property first
   249         // Use the system property first
   255         try {
   250         try {
   256 
   251 
   257             final String systemProp;
   252             final String systemProp;
   258             if (type.getName().equals(factoryId)) {
   253             if (type.getName().equals(factoryId)) {
   259                 systemProp = ss.getSystemProperty(factoryId);
   254                 systemProp = SecuritySupport.getSystemProperty(factoryId);
   260             } else {
   255             } else {
   261                 systemProp = System.getProperty(factoryId);
   256                 systemProp = System.getProperty(factoryId);
   262             }
   257             }
   263             if (systemProp != null) {
   258             if (systemProp != null) {
   264                 dPrint(()->"found system property, value=" + systemProp);
   259                 dPrint(()->"found system property, value=" + systemProp);
   275         String configFile = null;
   270         String configFile = null;
   276         try {
   271         try {
   277             if (firstTime) {
   272             if (firstTime) {
   278                 synchronized (cacheProps) {
   273                 synchronized (cacheProps) {
   279                     if (firstTime) {
   274                     if (firstTime) {
   280                         configFile = ss.getSystemProperty("java.home") + File.separator +
   275                         configFile = SecuritySupport.getSystemProperty("java.home") + File.separator +
   281                             "conf" + File.separator + "stax.properties";
   276                             "conf" + File.separator + "stax.properties";
   282                         final File fStax = new File(configFile);
   277                         final File fStax = new File(configFile);
   283                         firstTime = false;
   278                         firstTime = false;
   284                         if (ss.doesFileExist(fStax)) {
   279                         if (SecuritySupport.doesFileExist(fStax)) {
   285                             dPrint(()->"Read properties file "+fStax);
   280                             dPrint(()->"Read properties file "+fStax);
   286                             cacheProps.load(ss.getFileInputStream(fStax));
   281                             cacheProps.load(SecuritySupport.getFileInputStream(fStax));
   287                         }
   282                         }
   288                         else {
   283                         else {
   289                             configFile = ss.getSystemProperty("java.home") + File.separator +
   284                             configFile = SecuritySupport.getSystemProperty("java.home") + File.separator +
   290                                 "conf" + File.separator + "jaxp.properties";
   285                                 "conf" + File.separator + "jaxp.properties";
   291                             final File fJaxp = new File(configFile);
   286                             final File fJaxp = new File(configFile);
   292                             if (ss.doesFileExist(fJaxp)) {
   287                             if (SecuritySupport.doesFileExist(fJaxp)) {
   293                                 dPrint(()->"Read properties file "+fJaxp);
   288                                 dPrint(()->"Read properties file "+fJaxp);
   294                                 cacheProps.load(ss.getFileInputStream(fJaxp));
   289                                 cacheProps.load(SecuritySupport.getFileInputStream(fJaxp));
   295                             }
   290                             }
   296                         }
   291                         }
   297                     }
   292                     }
   298                 }
   293                 }
   299             }
   294             }