Author: mes
Date: 2010-02-01 17:09:02 -0800 (Mon, 01 Feb 2010)
New Revision: 19111
Modified:
cytoscape/trunk/src/cytoscape/plugin/PluginTracker.java
Log:
Fixed another potential NPE based on feedback received on cytoscape-discuss
Modified: cytoscape/trunk/src/cytoscape/plugin/PluginTracker.java
===================================================================
--- cytoscape/trunk/src/cytoscape/plugin/PluginTracker.java 2010-02-02
00:38:11 UTC (rev 19110)
+++ cytoscape/trunk/src/cytoscape/plugin/PluginTracker.java 2010-02-02
01:09:02 UTC (rev 19111)
@@ -51,6 +51,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
+import java.io.IOException;
import java.util.*;
@@ -70,14 +71,14 @@
* Xml file name
* @param Dir
* directory to to write xml file
- * @throws java.io.IOException
+ * @throws IOException
*/
- protected PluginTracker(File Dir, String FileName) throws
java.io.IOException, TrackerException {
+ protected PluginTracker(File Dir, String FileName) throws IOException,
TrackerException {
installFile = new File(Dir, FileName);
init();
}
- protected PluginTracker(File file) throws java.io.IOException,
TrackerException {
+ protected PluginTracker(File file) throws IOException, TrackerException
{
installFile = file;
init();
}
@@ -92,7 +93,7 @@
/*
* Sets up the xml doc for tracking.
*/
- private void init() throws java.io.IOException, TrackerException {
+ private void init() throws IOException, TrackerException {
corruptedElements = new HashSet<Element>();
if (PluginManager.usingWebstartManager()) {
@@ -108,19 +109,18 @@
try {
is = new FileInputStream(installFile);
trackerDoc = Builder.build(is,
installFile.toURI().toURL().toString());
- }
- finally {
+ } finally {
if (is != null) {
is.close();
}
}
removeMissingIdEntries();
write();
- } catch (JDOMException jde) {
+ validateTrackerDoc();
+ } catch (Exception jde) {
installFile.delete();
createCleanDoc();
- throw new TrackerException("Plugin tracking
file is corrupted. Please reinstall your plugins. Deleting " +
- installFile.getAbsolutePath(),
jde);
+ throw new TrackerException("Plugin tracking
file is corrupted. Please reinstall your plugins. Deleting " +
installFile.getAbsolutePath(), jde);
} finally {
createPluginTable();
}
@@ -130,6 +130,20 @@
}
}
+ /**
+ * Will throw an exception if the tracker document doesn't contain the
necessary
+ * elements. The goal is to force a dummy plugin table to be created.
+ */
+ private void validateTrackerDoc() {
+ for (PluginStatus ps: PluginStatus.values()) {
+ // several of these calls could also produce an NPE
+ Iterator<Element> iter =
trackerDoc.getRootElement().getChild(ps.getTagName()).getChildren().iterator();
+ if ( iter == null )
+ throw new NullPointerException("corrupted
tracker file");
+
+ }
+ }
+
private void createCleanDoc() {
logger.warn("Plugin tracker file: " +
installFile.getAbsolutePath());
trackerDoc = new Document();
@@ -353,12 +367,13 @@
return null;
}
}
-
+
private void createPluginTable() {
- this.infoObjMap = new java.util.HashMap<String, Element>();
+ this.infoObjMap = new HashMap<String, Element>();
for (PluginStatus ps: PluginStatus.values()) {
- // TODO how should a missing status tag be handled?
Probably the entire file
- // is bad and should be reinitialized
+ // A missing status tag should probably not happen
because we check for that in
+ // validateTrackerDoc(). Only if createCleanDoc() fails
to produce something usable
+ // will we run into problems here.
Iterator<Element> iter =
trackerDoc.getRootElement().getChild(ps.getTagName()).getChildren().iterator();
while (iter.hasNext()) {
@@ -414,7 +429,7 @@
writer.close();
}
}
- } catch (java.io.IOException E) {
+ } catch (IOException E) {
logger.warn("Error writing plugin status file
"+E.toString());
}
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.