summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/javax/xml/datatype/FactoryFinder.java
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src/main/java/javax/xml/datatype/FactoryFinder.java')
-rw-r--r--luni/src/main/java/javax/xml/datatype/FactoryFinder.java44
1 files changed, 24 insertions, 20 deletions
diff --git a/luni/src/main/java/javax/xml/datatype/FactoryFinder.java b/luni/src/main/java/javax/xml/datatype/FactoryFinder.java
index b65f412..1fbca2f 100644
--- a/luni/src/main/java/javax/xml/datatype/FactoryFinder.java
+++ b/luni/src/main/java/javax/xml/datatype/FactoryFinder.java
@@ -47,11 +47,30 @@ final class FactoryFinder {
/** <p>Debug flag to trace loading process.</p> */
private static boolean debug = false;
- /** <p>Cache properties for performance.</p> */
- private static Properties cacheProps = new Properties();
+ /**
+ * <p>Cache properties for performance. Use a static class to avoid double-checked
+ * locking.</p>
+ */
+ private static class CacheHolder {
- /** <p>First time requires initialization overhead.</p> */
- private static boolean firstTime = true;
+ private static Properties cacheProps = new Properties();
+
+ static {
+ String javah = System.getProperty("java.home");
+ String configFile = javah + File.separator + "lib" + File.separator + "jaxp.properties";
+ File f = new File(configFile);
+ if (f.exists()) {
+ if (debug) debugPrintln("Read properties file " + f);
+ try {
+ cacheProps.load(new FileInputStream(f));
+ } catch (Exception ex) {
+ if (debug) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+ }
/** Default columns per line. */
private static final int DEFAULT_LINE_LENGTH = 80;
@@ -177,22 +196,7 @@ final class FactoryFinder {
// try to read from $java.home/lib/jaxp.properties
try {
- String javah = System.getProperty("java.home");
- String configFile = javah + File.separator + "lib" + File.separator + "jaxp.properties";
- String factoryClassName = null;
- if (firstTime) {
- synchronized (cacheProps) {
- if (firstTime) {
- File f = new File(configFile);
- firstTime = false;
- if (f.exists()) {
- if (debug) debugPrintln("Read properties file " + f);
- cacheProps.load(new FileInputStream(f));
- }
- }
- }
- }
- factoryClassName = cacheProps.getProperty(factoryId);
+ String factoryClassName = CacheHolder.cacheProps.getProperty(factoryId);
if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
if (factoryClassName != null) {