summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-09-14 07:44:56 (EDT)
committer pelder2007-09-14 07:44:56 (EDT)
commitc60a2b540279071bf4843d9af047dda9fdfab313 (patch)
treeb3b482c718296d4213a9f862b495ad11b31d012b
parent54418eb6ce561850425f343fd436e51399633baf (diff)
downloadorg.eclipse.jet-c60a2b540279071bf4843d9af047dda9fdfab313.zip
org.eclipse.jet-c60a2b540279071bf4843d9af047dda9fdfab313.tar.gz
org.eclipse.jet-c60a2b540279071bf4843d9af047dda9fdfab313.tar.bz2
[203429] Prevent NPEs on initial workspace save
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java50
1 files changed, 30 insertions, 20 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java
index a944144..7d8c454 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/SavedStateManager.java
@@ -75,7 +75,7 @@ public class SavedStateManager implements ISaveParticipant
private final Plugin plugin;
/**
- * Track the new save number is required. A Project or Full save will request a new save number
+ * Track if a new save number is required. A doProjectSave save will request a new save number
* if this value is true, and then set this flag to false.
* This flag will be reset to true at the end of a successful full save.
*/
@@ -108,31 +108,39 @@ public class SavedStateManager implements ISaveParticipant
// check for directories to purge because of bug 201583...
final File stateDir = plugin.getStateLocation().toFile();
- final String currentSaveDirectory = getSaveDirectory(context.getSaveNumber()).toString();
- final File[] orphanedSaveDirs = stateDir.listFiles(new FilenameFilter() {
+ if (stateDir.exists() && stateDir.isDirectory())
+ {
+ final String currentSaveDirectory = getSaveDirectory(context.getSaveNumber()).toString();
+ final File[] orphanedSaveDirs = stateDir.listFiles(new FilenameFilter()
+ {
- public boolean accept(File dir, String name)
+ public boolean accept(File dir, String name)
+ {
+ return name.startsWith("save-") && !name.equals(currentSaveDirectory); //$NON-NLS-1$
+ }
+ });
+ for (int i = 0; i < orphanedSaveDirs.length; i++)
{
- return name.startsWith("save-") && !name.equals(currentSaveDirectory); //$NON-NLS-1$
- }});
- for (int i = 0; i < orphanedSaveDirs.length; i++)
- {
- deleteDirectory(orphanedSaveDirs[i]);
+ deleteDirectory(orphanedSaveDirs[i]);
+ }
}
}
}
private void deleteDirectory(File dir) {
- File[] files = dir.listFiles();
- for (int i = 0; i < files.length; i++)
+ if(dir.exists() && dir.isDirectory())
{
- if(files[i].isDirectory()) {
- deleteDirectory(files[i]);
- } else {
- files[i].delete();
+ File[] files = dir.listFiles();
+ for (int i = 0; files != null && i < files.length; i++)
+ {
+ if(files[i].isDirectory()) {
+ deleteDirectory(files[i]);
+ } else {
+ files[i].delete();
+ }
}
+ dir.delete();
}
- dir.delete();
}
/* (non-Javadoc)
@@ -164,11 +172,13 @@ public class SavedStateManager implements ISaveParticipant
case ISaveContext.PROJECT_SAVE:
// get the project related to this save operation
IProject project = context.getProject();
- WeakReference ref = (WeakReference)stateSaverByProject.get(project);
- if(ref != null) {
- doProjectSave(context, (IStateSaver)ref.get());
- }
+ // Don' bother saving the project. It gets lost in the next full save anyhow.
+ // worst case is that it gets rebuilt on open
+// WeakReference ref = (WeakReference)stateSaverByProject.get(project);
+// if(ref != null) {
+// doProjectSave(context, (IStateSaver)ref.get());
+// }
// PROJECT_SAVE happens only when the project is closed, forget about this project
stateSaverByProject.remove(project);
break;