8146271: File system contention in debug print via XPathFactory.newInstance
authoraefimov
Mon, 19 Dec 2016 18:45:58 +0300
changeset 42806 35843e3d5ef1
parent 42805 857b5e6eef37
child 42807 87aa931664b7
8146271: File system contention in debug print via XPathFactory.newInstance Reviewed-by: joehw, clanger
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java
jaxp/src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java
jaxp/src/java.xml/share/classes/javax/xml/parsers/FactoryFinder.java
jaxp/src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java
jaxp/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java
jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java
jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java	Mon Dec 19 18:45:58 2016 +0300
@@ -23,6 +23,8 @@
 
 package com.sun.org.apache.xalan.internal.utils;
 
+import java.util.function.Supplier;
+
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
  * It is package private and therefore is not exposed as part of the JAXP
@@ -46,9 +48,9 @@
 
 
     /** Prints a message to standard error if debugging is enabled. */
-    private static void debugPrintln(String msg) {
+    private static void debugPrintln(Supplier<String> msgGen) {
         if (DEBUG) {
-            System.err.println("JAXP: " + msg);
+            System.err.println("JAXP: " + msgGen.get());
         }
     } // debugPrintln(String)
 
@@ -125,8 +127,8 @@
         try{
             Class providerClass = findProviderClass(className, cl, doFallback);
             Object instance = providerClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
+            debugPrintln(()->"created new instance of " + providerClass +
+                             " using ClassLoader: " + cl);
             return instance;
         } catch (ClassNotFoundException x) {
             throw new ConfigurationError(
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java	Mon Dec 19 18:45:58 2016 +0300
@@ -20,6 +20,8 @@
 
 package com.sun.org.apache.xerces.internal.utils;
 
+import java.util.function.Supplier;
+
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
  * It is package private and therefore is not exposed as part of the JAXP
@@ -61,9 +63,9 @@
     } // isDebugEnabled()
 
     /** Prints a message to standard error if debugging is enabled. */
-    private static void debugPrintln(String msg) {
+    private static void debugPrintln(Supplier<String> msgGen) {
         if (DEBUG) {
-            System.err.println("XERCES: " + msg);
+            System.err.println("XERCES: " + msgGen.get());
         }
     } // debugPrintln(String)
 
@@ -155,8 +157,8 @@
         try{
             Class providerClass = findProviderClass(className, cl, doFallback);
             Object instance = providerClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
+            debugPrintln(()->"created new instance of " + providerClass +
+                             " using ClassLoader: " + cl);
             return instance;
         } catch (ClassNotFoundException x) {
             throw new ConfigurationError(
--- a/jaxp/src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java	Mon Dec 19 18:45:58 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
 import java.util.Properties;
 import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
+import java.util.function.Supplier;
 
 /**
  * <p>Implements pluggable Datatypes.</p>
@@ -80,9 +81,9 @@
         }
     }
 
-    private static void dPrint(String msg) {
+    private static void dPrint(Supplier<String> msgGen) {
         if (debug) {
-            System.err.println("JAXP: " + msg);
+            System.err.println("JAXP: " + msgGen.get());
         }
     }
 
@@ -190,10 +191,9 @@
                 throw new ClassCastException(className + " cannot be cast to " + type.getName());
             }
             Object instance = providerClass.newInstance();
-            if (debug) {    // Extra check to avoid computing cl strings
-                dPrint("created new instance of " + providerClass +
-                       " using ClassLoader: " + cl);
-            }
+            final ClassLoader clD = cl;
+            dPrint(()->"created new instance of " + providerClass +
+                       " using ClassLoader: " + clD);
             return type.cast(instance);
         }
         catch (ClassNotFoundException x) {
@@ -223,13 +223,13 @@
         throws DatatypeConfigurationException
     {
         final String factoryId = type.getName();
-        dPrint("find factoryId =" + factoryId);
+        dPrint(()->"find factoryId =" + factoryId);
 
         // Use the system property first
         try {
             String systemProp = ss.getSystemProperty(factoryId);
             if (systemProp != null) {
-                dPrint("found system property, value=" + systemProp);
+                dPrint(()->"found system property, value=" + systemProp);
                 return newInstance(type, systemProp, null, true);
             }
         }
@@ -247,7 +247,7 @@
                         File f = new File(configFile);
                         firstTime = false;
                         if (ss.doesFileExist(f)) {
-                            dPrint("Read properties file "+f);
+                            dPrint(()->"Read properties file "+f);
                             cacheProps.load(ss.getFileInputStream(f));
                         }
                     }
@@ -256,7 +256,7 @@
             final String factoryClassName = cacheProps.getProperty(factoryId);
 
             if (factoryClassName != null) {
-                dPrint("found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName);
+                dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName);
                 return newInstance(type, factoryClassName, null, true);
             }
         }
@@ -274,7 +274,7 @@
                 "Provider for " + factoryId + " cannot be found");
         }
 
-        dPrint("loaded from fallback value: " + fallbackClassName);
+        dPrint(()->"loaded from fallback value: " + fallbackClassName);
         return newInstance(type, fallbackClassName, null, true);
     }
 
--- a/jaxp/src/java.xml/share/classes/javax/xml/parsers/FactoryFinder.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/parsers/FactoryFinder.java	Mon Dec 19 18:45:58 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
 import java.util.Properties;
 import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
+import java.util.function.Supplier;
 
 /**
  * <p>Implements pluggable Parsers.</p>
@@ -80,9 +81,9 @@
         }
     }
 
-    private static void dPrint(String msg) {
+    private static void dPrint(Supplier<String> msgGen) {
         if (debug) {
-            System.err.println("JAXP: " + msg);
+            System.err.println("JAXP: " + msgGen.get());
         }
     }
 
@@ -190,10 +191,9 @@
                 throw new ClassCastException(className + " cannot be cast to " + type.getName());
             }
             Object instance = providerClass.newInstance();
-            if (debug) {    // Extra check to avoid computing cl strings
-                dPrint("created new instance of " + providerClass +
-                       " using ClassLoader: " + cl);
-            }
+            final ClassLoader clD = cl;
+            dPrint(()->"created new instance of " + providerClass +
+                       " using ClassLoader: " + clD);
             return type.cast(instance);
         }
         catch (ClassNotFoundException x) {
@@ -222,13 +222,13 @@
         throws FactoryConfigurationError
     {
         final String factoryId = type.getName();
-        dPrint("find factoryId =" + factoryId);
+        dPrint(()->"find factoryId =" + factoryId);
 
         // Use the system property first
         try {
             String systemProp = ss.getSystemProperty(factoryId);
             if (systemProp != null) {
-                dPrint("found system property, value=" + systemProp);
+                dPrint(()->"found system property, value=" + systemProp);
                 return newInstance(type, systemProp, null, true);
             }
         }
@@ -246,7 +246,7 @@
                         File f = new File(configFile);
                         firstTime = false;
                         if (ss.doesFileExist(f)) {
-                            dPrint("Read properties file "+f);
+                            dPrint(()->"Read properties file "+f);
                             cacheProps.load(ss.getFileInputStream(f));
                         }
                     }
@@ -255,7 +255,7 @@
             final String factoryClassName = cacheProps.getProperty(factoryId);
 
             if (factoryClassName != null) {
-                dPrint("found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName);
+                dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName);
                 return newInstance(type, factoryClassName, null, true);
             }
         }
@@ -273,7 +273,7 @@
                 "Provider for " + factoryId + " cannot be found");
         }
 
-        dPrint("loaded from fallback value: " + fallbackClassName);
+        dPrint(()->"loaded from fallback value: " + fallbackClassName);
         return newInstance(type, fallbackClassName, null, true);
     }
 
--- a/jaxp/src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java	Mon Dec 19 18:45:58 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
 import java.util.Properties;
 import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
+import java.util.function.Supplier;
 
 /**
  * <p>Implements pluggable streams.</p>
@@ -81,9 +82,9 @@
         }
     }
 
-    private static void dPrint(String msg) {
+    private static void dPrint(Supplier<String> msgGen) {
         if (debug) {
-            System.err.println("JAXP: " + msg);
+            System.err.println("JAXP: " + msgGen.get());
         }
     }
 
@@ -191,10 +192,9 @@
                 throw new ClassCastException(className + " cannot be cast to " + type.getName());
             }
             Object instance = providerClass.newInstance();
-            if (debug) {    // Extra check to avoid computing cl strings
-                dPrint("created new instance of " + providerClass +
-                       " using ClassLoader: " + cl);
-            }
+            final ClassLoader clD = cl;
+            dPrint(()->"created new instance of " + providerClass +
+                       " using ClassLoader: " + clD);
             return type.cast(instance);
         }
         catch (ClassNotFoundException x) {
@@ -249,7 +249,7 @@
     static <T> T find(Class<T> type, String factoryId, ClassLoader cl, String fallbackClassName)
         throws FactoryConfigurationError
     {
-        dPrint("find factoryId =" + factoryId);
+        dPrint(()->"find factoryId =" + factoryId);
 
         // Use the system property first
         try {
@@ -261,7 +261,7 @@
                 systemProp = System.getProperty(factoryId);
             }
             if (systemProp != null) {
-                dPrint("found system property, value=" + systemProp);
+                dPrint(()->"found system property, value=" + systemProp);
                 return newInstance(type, systemProp, cl, true);
             }
         }
@@ -279,19 +279,19 @@
                     if (firstTime) {
                         configFile = ss.getSystemProperty("java.home") + File.separator +
                             "lib" + File.separator + "stax.properties";
-                        File f = new File(configFile);
+                        final File fStax = new File(configFile);
                         firstTime = false;
-                        if (ss.doesFileExist(f)) {
-                            dPrint("Read properties file "+f);
-                            cacheProps.load(ss.getFileInputStream(f));
+                        if (ss.doesFileExist(fStax)) {
+                            dPrint(()->"Read properties file "+fStax);
+                            cacheProps.load(ss.getFileInputStream(fStax));
                         }
                         else {
                             configFile = ss.getSystemProperty("java.home") + File.separator +
                                 "conf" + File.separator + "jaxp.properties";
-                            f = new File(configFile);
-                            if (ss.doesFileExist(f)) {
-                                dPrint("Read properties file "+f);
-                                cacheProps.load(ss.getFileInputStream(f));
+                            final File fJaxp = new File(configFile);
+                            if (ss.doesFileExist(fJaxp)) {
+                                dPrint(()->"Read properties file "+fJaxp);
+                                cacheProps.load(ss.getFileInputStream(fJaxp));
                             }
                         }
                     }
@@ -300,7 +300,8 @@
             final String factoryClassName = cacheProps.getProperty(factoryId);
 
             if (factoryClassName != null) {
-                dPrint("found in " + configFile + " value=" + factoryClassName);
+                final String foundIn = configFile;
+                dPrint(()->"found in " + foundIn + " value=" + factoryClassName);
                 return newInstance(type, factoryClassName, cl, true);
             }
         }
@@ -325,7 +326,7 @@
                 "Provider for " + factoryId + " cannot be found", null);
         }
 
-        dPrint("loaded from fallback value: " + fallbackClassName);
+        dPrint(()->"loaded from fallback value: " + fallbackClassName);
         return newInstance(type, fallbackClassName, cl, true);
     }
 
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java	Mon Dec 19 18:45:58 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
 import java.util.Properties;
 import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
+import java.util.function.Supplier;
 
 /**
  * <p>Implements pluggable Datatypes.</p>
@@ -83,9 +84,9 @@
         }
     }
 
-    private static void dPrint(String msg) {
+    private static void dPrint(Supplier<String> msgGen) {
         if (debug) {
-            System.err.println("JAXP: " + msg);
+            System.err.println("JAXP: " + msgGen.get());
         }
     }
 
@@ -177,10 +178,9 @@
             if (instance == null) {
                 instance = providerClass.newInstance();
             }
-            if (debug) {    // Extra check to avoid computing cl strings
-                dPrint("created new instance of " + providerClass +
-                       " using ClassLoader: " + cl);
-            }
+            final ClassLoader clD = cl;
+            dPrint(()->"created new instance of " + providerClass +
+                       " using ClassLoader: " + clD);
             return type.cast(instance);
         }
         catch (ClassNotFoundException x) {
@@ -255,12 +255,12 @@
 
         final String factoryId = type.getName();
 
-        dPrint("find factoryId =" + factoryId);
+        dPrint(()->"find factoryId =" + factoryId);
         // Use the system property first
         try {
             String systemProp = ss.getSystemProperty(factoryId);
             if (systemProp != null) {
-                dPrint("found system property, value=" + systemProp);
+                dPrint(()->"found system property, value=" + systemProp);
                 return newInstance(type, systemProp, null, true, true);
             }
         }
@@ -278,7 +278,7 @@
                         File f = new File(configFile);
                         firstTime = false;
                         if (ss.doesFileExist(f)) {
-                            dPrint("Read properties file "+f);
+                            dPrint(()->"Read properties file "+f);
                             cacheProps.load(ss.getFileInputStream(f));
                         }
                     }
@@ -287,7 +287,7 @@
             final String factoryClassName = cacheProps.getProperty(factoryId);
 
             if (factoryClassName != null) {
-                dPrint("found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName);
+                dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName);
                 return newInstance(type, factoryClassName, null, true, true);
             }
         }
@@ -305,7 +305,7 @@
                 "Provider for " + factoryId + " cannot be found");
         }
 
-        dPrint("loaded from fallback value: " + fallbackClassName);
+        dPrint(()->"loaded from fallback value: " + fallbackClassName);
         return newInstance(type, fallbackClassName, null, true, true);
     }
 
--- a/jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java	Mon Dec 19 18:45:58 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
 import java.util.Properties;
 import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
+import java.util.function.Supplier;
 
 /**
  * Implementation of {@link SchemaFactory#newInstance(String)}.
@@ -72,11 +73,11 @@
     /**
      * <p>Conditional debug printing.</p>
      *
-     * @param msg to print
+     * @param msgGen Supplier function that returns debug message
      */
-    private static void debugPrintln(String msg) {
+    private static void debugPrintln(Supplier<String> msgGen) {
         if (debug) {
-            System.err.println("JAXP: " + msg);
+            System.err.println("JAXP: " + msgGen.get());
         }
     }
 
@@ -106,7 +107,7 @@
     private void debugDisplayClassLoader() {
         try {
             if( classLoader == ss.getContextClassLoader() ) {
-                debugPrintln("using thread context class loader ("+classLoader+") for search");
+                debugPrintln(()->"using thread context class loader ("+classLoader+") for search");
                 return;
             }
         } catch( Throwable unused ) {
@@ -114,11 +115,11 @@
         }
 
         if( classLoader==ClassLoader.getSystemClassLoader() ) {
-            debugPrintln("using system class loader ("+classLoader+") for search");
+            debugPrintln(()->"using system class loader ("+classLoader+") for search");
             return;
         }
 
-        debugPrintln("using class loader ("+classLoader+") for search");
+        debugPrintln(()->"using class loader ("+classLoader+") for search");
     }
 
     /**
@@ -142,9 +143,9 @@
         }
         SchemaFactory f = _newFactory(schemaLanguage);
         if (f != null) {
-            debugPrintln("factory '" + f.getClass().getName() + "' was found for " + schemaLanguage);
+            debugPrintln(()->"factory '" + f.getClass().getName() + "' was found for " + schemaLanguage);
         } else {
-            debugPrintln("unable to find a factory for " + schemaLanguage);
+            debugPrintln(()->"unable to find a factory for " + schemaLanguage);
         }
         return f;
     }
@@ -163,17 +164,17 @@
 
         // system property look up
         try {
-            debugPrintln("Looking up system property '"+propertyName+"'" );
+            debugPrintln(()->"Looking up system property '"+propertyName+"'" );
             String r = ss.getSystemProperty(propertyName);
             if(r!=null) {
-                debugPrintln("The value is '"+r+"'");
+                debugPrintln(()->"The value is '"+r+"'");
                 sf = createInstance(r, true);
                 if(sf!=null)    return sf;
             } else
-                debugPrintln("The property is undefined.");
+                debugPrintln(()->"The property is undefined.");
         } catch( Throwable t ) {
             if( debug ) {
-                debugPrintln("failed to look up system property '"+propertyName+"'" );
+                debugPrintln(()->"failed to look up system property '"+propertyName+"'" );
                 t.printStackTrace();
             }
         }
@@ -191,14 +192,14 @@
                         File f=new File( configFile );
                         firstTime = false;
                         if(ss.doesFileExist(f)){
-                            debugPrintln("Read properties file " + f);
+                            debugPrintln(()->"Read properties file " + f);
                             cacheProps.load(ss.getFileInputStream(f));
                         }
                     }
                 }
             }
             final String factoryClassName = cacheProps.getProperty(propertyName);
-            debugPrintln("found " + factoryClassName + " in $java.home/conf/jaxp.properties");
+            debugPrintln(()->"found " + factoryClassName + " in $java.home/conf/jaxp.properties");
 
             if (factoryClassName != null) {
                 sf = createInstance(factoryClassName, true);
@@ -225,11 +226,11 @@
 
         // platform default
         if(schemaLanguage.equals("http://www.w3.org/2001/XMLSchema")) {
-            debugPrintln("attempting to use the platform default XML Schema validator");
+            debugPrintln(()->"attempting to use the platform default XML Schema validator");
             return createInstance("com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory", true);
         }
 
-        debugPrintln("all things were tried, but none was found. bailing out.");
+        debugPrintln(()->"all things were tried, but none was found. bailing out.");
         return null;
     }
 
@@ -280,15 +281,15 @@
     SchemaFactory createInstance( String className, boolean useServicesMechanism ) {
         SchemaFactory schemaFactory = null;
 
-        debugPrintln("createInstance(" + className + ")");
+        debugPrintln(()->"createInstance(" + className + ")");
 
         // get Class from className
         Class<?> clazz = createClass(className);
         if (clazz == null) {
-                debugPrintln("failed to getClass(" + className + ")");
+                debugPrintln(()->"failed to getClass(" + className + ")");
                 return null;
         }
-        debugPrintln("loaded " + className + " from " + which(clazz));
+        debugPrintln(()->"loaded " + className + " from " + which(clazz));
 
         // instantiate Class as a SchemaFactory
         try {
@@ -303,19 +304,19 @@
                     schemaFactory = (SchemaFactory) clazz.newInstance();
                 }
         } catch (ClassCastException classCastException) {
-                debugPrintln("could not instantiate " + clazz.getName());
+                debugPrintln(()->"could not instantiate " + clazz.getName());
                 if (debug) {
                         classCastException.printStackTrace();
                 }
                 return null;
         } catch (IllegalAccessException illegalAccessException) {
-                debugPrintln("could not instantiate " + clazz.getName());
+                debugPrintln(()->"could not instantiate " + clazz.getName());
                 if (debug) {
                         illegalAccessException.printStackTrace();
                 }
                 return null;
         } catch (InstantiationException instantiationException) {
-                debugPrintln("could not instantiate " + clazz.getName());
+                debugPrintln(()->"could not instantiate " + clazz.getName());
                 if (debug) {
                         instantiationException.printStackTrace();
                 }
--- a/jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java	Mon Dec 19 11:13:32 2016 +0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java	Mon Dec 19 18:45:58 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
 import java.util.Properties;
 import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
+import java.util.function.Supplier;
 
 /**
  * Implementation of {@link XPathFactory#newInstance(String)}.
@@ -69,11 +70,11 @@
     /**
      * <p>Conditional debug printing.</p>
      *
-     * @param msg to print
+     * @param msgGen Supplier function that returns debug message
      */
-    private static void debugPrintln(String msg) {
+    private static void debugPrintln(Supplier<String> msgGen) {
         if (debug) {
-            System.err.println("JAXP: " + msg);
+            System.err.println("JAXP: " + msgGen.get());
         }
     }
 
@@ -102,7 +103,7 @@
     private void debugDisplayClassLoader() {
         try {
             if( classLoader == ss.getContextClassLoader() ) {
-                debugPrintln("using thread context class loader ("+classLoader+") for search");
+                debugPrintln(() -> "using thread context class loader ("+classLoader+") for search");
                 return;
             }
         } catch( Throwable unused ) {
@@ -110,11 +111,11 @@
         }
 
         if( classLoader==ClassLoader.getSystemClassLoader() ) {
-            debugPrintln("using system class loader ("+classLoader+") for search");
+            debugPrintln(() -> "using system class loader ("+classLoader+") for search");
             return;
         }
 
-        debugPrintln("using class loader ("+classLoader+") for search");
+        debugPrintln(() -> "using class loader ("+classLoader+") for search");
     }
 
     /**
@@ -135,9 +136,9 @@
         }
         XPathFactory f = _newFactory(uri);
         if (f != null) {
-            debugPrintln("factory '" + f.getClass().getName() + "' was found for " + uri);
+            debugPrintln(()->"factory '" + f.getClass().getName() + "' was found for " + uri);
         } else {
-            debugPrintln("unable to find a factory for " + uri);
+            debugPrintln(()->"unable to find a factory for " + uri);
         }
         return f;
     }
@@ -156,19 +157,19 @@
 
         // system property look up
         try {
-            debugPrintln("Looking up system property '"+propertyName+"'" );
+            debugPrintln(()->"Looking up system property '"+propertyName+"'" );
             String r = ss.getSystemProperty(propertyName);
             if(r!=null) {
-                debugPrintln("The value is '"+r+"'");
+                debugPrintln(()->"The value is '"+r+"'");
                 xpathFactory = createInstance(r, true);
                 if (xpathFactory != null) {
                     return xpathFactory;
                 }
             } else
-                debugPrintln("The property is undefined.");
+                debugPrintln(()->"The property is undefined.");
         } catch( Throwable t ) {
             if( debug ) {
-                debugPrintln("failed to look up system property '"+propertyName+"'" );
+                debugPrintln(()->"failed to look up system property '"+propertyName+"'" );
                 t.printStackTrace();
             }
         }
@@ -185,14 +186,14 @@
                         File f=new File( configFile );
                         firstTime = false;
                         if(ss.doesFileExist(f)){
-                            debugPrintln("Read properties file " + f);
+                            debugPrintln(()->"Read properties file " + f);
                             cacheProps.load(ss.getFileInputStream(f));
                         }
                     }
                 }
             }
             final String factoryClassName = cacheProps.getProperty(propertyName);
-            debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
+            debugPrintln(()->"found " + factoryClassName + " in $java.home/jaxp.properties");
 
             if (factoryClassName != null) {
                 xpathFactory = createInstance(factoryClassName, true);
@@ -220,11 +221,11 @@
 
         // platform default
         if(uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) {
-            debugPrintln("attempting to use the platform default W3C DOM XPath lib");
+            debugPrintln(()->"attempting to use the platform default W3C DOM XPath lib");
             return createInstance("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", true);
         }
 
-        debugPrintln("all things were tried, but none was found. bailing out.");
+        debugPrintln(()->"all things were tried, but none was found. bailing out.");
         return null;
     }
 
@@ -280,15 +281,15 @@
     {
         XPathFactory xPathFactory = null;
 
-        debugPrintln("createInstance(" + className + ")");
+        debugPrintln(()->"createInstance(" + className + ")");
 
         // get Class from className
         Class<?> clazz = createClass(className);
         if (clazz == null) {
-            debugPrintln("failed to getClass(" + className + ")");
+            debugPrintln(()->"failed to getClass(" + className + ")");
             return null;
         }
-        debugPrintln("loaded " + className + " from " + which(clazz));
+        debugPrintln(()->"loaded " + className + " from " + which(clazz));
 
         // instantiate Class as a XPathFactory
         try {
@@ -299,19 +300,19 @@
                 xPathFactory = (XPathFactory) clazz.newInstance();
             }
         } catch (ClassCastException classCastException) {
-                debugPrintln("could not instantiate " + clazz.getName());
+                debugPrintln(()->"could not instantiate " + clazz.getName());
                 if (debug) {
                         classCastException.printStackTrace();
                 }
                 return null;
         } catch (IllegalAccessException illegalAccessException) {
-                debugPrintln("could not instantiate " + clazz.getName());
+                debugPrintln(()->"could not instantiate " + clazz.getName());
                 if (debug) {
                         illegalAccessException.printStackTrace();
                 }
                 return null;
         } catch (InstantiationException instantiationException) {
-                debugPrintln("could not instantiate " + clazz.getName());
+                debugPrintln(()->"could not instantiate " + clazz.getName());
                 if (debug) {
                         instantiationException.printStackTrace();
                 }