mrglavas 2004/06/06 16:33:19
Modified: java/src/org/apache/xml/serialize ObjectFactory.java
java/src/org/apache/html/dom ObjectFactory.java
java/src/org/apache/xerces/xinclude ObjectFactory.java
java/src/org/apache/xerces/parsers ObjectFactory.java
java/src/org/apache/xerces/impl/dv ObjectFactory.java
java/src/org/apache/xerces/dom ObjectFactory.java
Log:
Fixing another potential memory leak. The input stream
used for loading properties may never be closed if an
IOException is thrown while reading from it. Adding
finally blocks so that the input stream will always
be closed.
Revision Changes Path
1.7 +32 -12 xml-xerces/java/src/org/apache/xml/serialize/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/ObjectFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ObjectFactory.java 6 Jun 2004 15:21:25 -0000 1.6
+++ ObjectFactory.java 6 Jun 2004 23:33:19 -0000 1.7
@@ -157,9 +157,10 @@
fLastModified = -1;
fXercesProperties = null;
}
-
+
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
+ FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
@@ -183,32 +184,51 @@
if(loadProperties) {
// must never have attempted to read xerces.properties
before (or it's outdeated)
fXercesProperties = new Properties();
- FileInputStream fis = ss.getFileInputStream(propertiesFile);
+ fis = ss.getFileInputStream(propertiesFile);
fXercesProperties.load(fis);
- fis.close();
}
- } catch (Exception x) {
- fXercesProperties = null;
- fLastModified = -1;
+ } catch (Exception x) {
+ fXercesProperties = null;
+ fLastModified = -1;
// assert(x instanceof FileNotFoundException
- // || x instanceof SecurityException)
- // In both cases, ignore and continue w/ next location
- }
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
}
if(fXercesProperties != null) {
factoryClassName = fXercesProperties.getProperty(factoryId);
}
} else {
+ FileInputStream fis = null;
try {
- FileInputStream fis = ss.getFileInputStream(new
File(propertiesFilename));
+ fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
- fis.close();
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
}
}
if (factoryClassName != null) {
1.7 +32 -12 xml-xerces/java/src/org/apache/html/dom/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/html/dom/ObjectFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ObjectFactory.java 6 Jun 2004 15:21:25 -0000 1.6
+++ ObjectFactory.java 6 Jun 2004 23:33:19 -0000 1.7
@@ -157,9 +157,10 @@
fLastModified = -1;
fXercesProperties = null;
}
-
+
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
+ FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
@@ -183,32 +184,51 @@
if(loadProperties) {
// must never have attempted to read xerces.properties
before (or it's outdeated)
fXercesProperties = new Properties();
- FileInputStream fis = ss.getFileInputStream(propertiesFile);
+ fis = ss.getFileInputStream(propertiesFile);
fXercesProperties.load(fis);
- fis.close();
}
- } catch (Exception x) {
- fXercesProperties = null;
- fLastModified = -1;
+ } catch (Exception x) {
+ fXercesProperties = null;
+ fLastModified = -1;
// assert(x instanceof FileNotFoundException
- // || x instanceof SecurityException)
- // In both cases, ignore and continue w/ next location
- }
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
}
if(fXercesProperties != null) {
factoryClassName = fXercesProperties.getProperty(factoryId);
}
} else {
+ FileInputStream fis = null;
try {
- FileInputStream fis = ss.getFileInputStream(new
File(propertiesFilename));
+ fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
- fis.close();
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
}
}
if (factoryClassName != null) {
1.6 +32 -12
xml-xerces/java/src/org/apache/xerces/xinclude/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/xinclude/ObjectFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ObjectFactory.java 6 Jun 2004 15:21:25 -0000 1.5
+++ ObjectFactory.java 6 Jun 2004 23:33:19 -0000 1.6
@@ -157,9 +157,10 @@
fLastModified = -1;
fXercesProperties = null;
}
-
+
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
+ FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
@@ -183,32 +184,51 @@
if(loadProperties) {
// must never have attempted to read xerces.properties
before (or it's outdeated)
fXercesProperties = new Properties();
- FileInputStream fis = ss.getFileInputStream(propertiesFile);
+ fis = ss.getFileInputStream(propertiesFile);
fXercesProperties.load(fis);
- fis.close();
}
- } catch (Exception x) {
- fXercesProperties = null;
- fLastModified = -1;
+ } catch (Exception x) {
+ fXercesProperties = null;
+ fLastModified = -1;
// assert(x instanceof FileNotFoundException
- // || x instanceof SecurityException)
- // In both cases, ignore and continue w/ next location
- }
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
}
if(fXercesProperties != null) {
factoryClassName = fXercesProperties.getProperty(factoryId);
}
} else {
+ FileInputStream fis = null;
try {
- FileInputStream fis = ss.getFileInputStream(new
File(propertiesFilename));
+ fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
- fis.close();
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
}
}
if (factoryClassName != null) {
1.7 +32 -12 xml-xerces/java/src/org/apache/xerces/parsers/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/ObjectFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ObjectFactory.java 6 Jun 2004 15:21:25 -0000 1.6
+++ ObjectFactory.java 6 Jun 2004 23:33:19 -0000 1.7
@@ -157,9 +157,10 @@
fLastModified = -1;
fXercesProperties = null;
}
-
+
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
+ FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
@@ -183,32 +184,51 @@
if(loadProperties) {
// must never have attempted to read xerces.properties
before (or it's outdeated)
fXercesProperties = new Properties();
- FileInputStream fis = ss.getFileInputStream(propertiesFile);
+ fis = ss.getFileInputStream(propertiesFile);
fXercesProperties.load(fis);
- fis.close();
}
- } catch (Exception x) {
- fXercesProperties = null;
- fLastModified = -1;
+ } catch (Exception x) {
+ fXercesProperties = null;
+ fLastModified = -1;
// assert(x instanceof FileNotFoundException
- // || x instanceof SecurityException)
- // In both cases, ignore and continue w/ next location
- }
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
}
if(fXercesProperties != null) {
factoryClassName = fXercesProperties.getProperty(factoryId);
}
} else {
+ FileInputStream fis = null;
try {
- FileInputStream fis = ss.getFileInputStream(new
File(propertiesFilename));
+ fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
- fis.close();
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
}
}
if (factoryClassName != null) {
1.7 +32 -12 xml-xerces/java/src/org/apache/xerces/impl/dv/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/ObjectFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ObjectFactory.java 6 Jun 2004 15:21:25 -0000 1.6
+++ ObjectFactory.java 6 Jun 2004 23:33:19 -0000 1.7
@@ -157,9 +157,10 @@
fLastModified = -1;
fXercesProperties = null;
}
-
+
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
+ FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
@@ -183,32 +184,51 @@
if(loadProperties) {
// must never have attempted to read xerces.properties
before (or it's outdeated)
fXercesProperties = new Properties();
- FileInputStream fis = ss.getFileInputStream(propertiesFile);
+ fis = ss.getFileInputStream(propertiesFile);
fXercesProperties.load(fis);
- fis.close();
}
- } catch (Exception x) {
- fXercesProperties = null;
- fLastModified = -1;
+ } catch (Exception x) {
+ fXercesProperties = null;
+ fLastModified = -1;
// assert(x instanceof FileNotFoundException
- // || x instanceof SecurityException)
- // In both cases, ignore and continue w/ next location
- }
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
}
if(fXercesProperties != null) {
factoryClassName = fXercesProperties.getProperty(factoryId);
}
} else {
+ FileInputStream fis = null;
try {
- FileInputStream fis = ss.getFileInputStream(new
File(propertiesFilename));
+ fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
- fis.close();
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
}
}
if (factoryClassName != null) {
1.7 +32 -12 xml-xerces/java/src/org/apache/xerces/dom/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ObjectFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ObjectFactory.java 6 Jun 2004 15:21:25 -0000 1.6
+++ ObjectFactory.java 6 Jun 2004 23:33:19 -0000 1.7
@@ -157,9 +157,10 @@
fLastModified = -1;
fXercesProperties = null;
}
-
+
synchronized (ObjectFactory.class) {
boolean loadProperties = false;
+ FileInputStream fis = null;
try {
// file existed last time
if(fLastModified >= 0) {
@@ -183,32 +184,51 @@
if(loadProperties) {
// must never have attempted to read xerces.properties
before (or it's outdeated)
fXercesProperties = new Properties();
- FileInputStream fis = ss.getFileInputStream(propertiesFile);
+ fis = ss.getFileInputStream(propertiesFile);
fXercesProperties.load(fis);
- fis.close();
}
- } catch (Exception x) {
- fXercesProperties = null;
- fLastModified = -1;
+ } catch (Exception x) {
+ fXercesProperties = null;
+ fLastModified = -1;
// assert(x instanceof FileNotFoundException
- // || x instanceof SecurityException)
- // In both cases, ignore and continue w/ next location
- }
+ // || x instanceof SecurityException)
+ // In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
+ }
}
if(fXercesProperties != null) {
factoryClassName = fXercesProperties.getProperty(factoryId);
}
} else {
+ FileInputStream fis = null;
try {
- FileInputStream fis = ss.getFileInputStream(new
File(propertiesFilename));
+ fis = ss.getFileInputStream(new File(propertiesFilename));
Properties props = new Properties();
props.load(fis);
- fis.close();
factoryClassName = props.getProperty(factoryId);
} catch (Exception x) {
// assert(x instanceof FileNotFoundException
// || x instanceof SecurityException)
// In both cases, ignore and continue w/ next location
+ }
+ finally {
+ // try to close the input stream if one was opened.
+ if (fis != null) {
+ try {
+ fis.close();
+ }
+ // Ignore the exception.
+ catch (IOException exc) {}
+ }
}
}
if (factoryClassName != null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]