Author: scabanovich
Date: 2012-10-05 18:47:08 -0400 (Fri, 05 Oct 2012)
New Revision: 44349
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
Log:
File.listFiles() may return null. Check File.isDirectory() is not 100% safe; another
thread or process may remove the directory right between File.isDirectory() and
File.listFiles().
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2012-10-05
21:41:06 UTC (rev 44348)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2012-10-05
22:47:08 UTC (rev 44349)
@@ -149,13 +149,28 @@
return (getParent() == null) ? null : ((FolderImpl)getParent()).getProject();
}
+ /**
+ * May return null.
+ *
+ * @return
+ */
private File[] getFiles() {
File f = getFile();
if(f == null) return null;
if (!f.isDirectory()) return new File[0];
- return f.listFiles();
+ return f.listFiles(); //May return null if another thread removes directory right
after the check.
}
+ private void fillMap(Map<String, File> m) {
+ File[] fs = getFiles();
+ if(fs != null) {
+ for (File f: fs) {
+ String p = FilePathHelper.toPathPath(f.getName());
+ m.put(p, f);
+ }
+ }
+ }
+
public void set(String name, String value) {
if(XModelObjectConstants.XML_ATTR_NAME.equals(name) && isActive()) {
if(value != null && !value.equals(get(name))) copy();
@@ -368,13 +383,9 @@
} catch (CoreException ex) {
ModelPlugin.getPluginLog().logError("Exception caught in
FolderImpl.update()"); //$NON-NLS-1$
}
-
- File[] fs = getFiles();
- for (int i = 0; i < fs.length; i++) {
- String p = FilePathHelper.toPathPath(fs[i].getName());
- mf.put(p, fs[i]);
- }
+ fillMap(mf);
+
Map<String,XModelObject> mc = children.getObjectsMap();
updateAuxiliary(mc, mf);
@@ -856,12 +867,8 @@
}
if(!f.exists()) f.mkdirs();
}
- File[] fs = getFiles();
Map<String,File> t = new HashMap<String,File>();
- for (int i = 0; i < fs.length; i++) {
- String p = FilePathHelper.toPathPath(fs[i].getName());
- t.put(p, fs[i]);
- }
+ fillMap(t);
FileSystemPeer peer = getFileSystem().getPeer();
peer.register(f);
XModelObject[] cs = getChildren();
Show replies by date