1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

[203501] fix NPE in PFMetadataLocation

This commit is contained in:
David Dykstal 2007-12-19 21:32:16 +00:00
parent 54b801b1c9
commit 1c1fb2d1bd
2 changed files with 16 additions and 7 deletions

View file

@ -49,6 +49,7 @@ class PFMetadataLocation implements PFPersistenceLocation {
public PFPersistenceLocation[] getChildren() {
File[] members = _baseFolder.listFiles();
if (members == null) members = new File[0];
List children = new ArrayList(members.length);
for (int i = 0; i < members.length; i++) {
File member = members[i];
@ -87,6 +88,7 @@ class PFMetadataLocation implements PFPersistenceLocation {
public void keepChildren(Set keepSet) {
File[] children = _baseFolder.listFiles();
if (children == null) children = new File[0];
for (int i = 0; i < children.length; i++) {
File child = children[i];
if (!keepSet.contains(child.getName())) {
@ -96,6 +98,7 @@ class PFMetadataLocation implements PFPersistenceLocation {
}
public void setContents(InputStream stream) {
ensure();
OutputStream out = null;
try {
out = new FileOutputStream(getContentsFile());
@ -130,6 +133,7 @@ class PFMetadataLocation implements PFPersistenceLocation {
* @param file the file to delete.
*/
private void deleteFile(File file) {
if (file.exists()) {
if (file.isDirectory()) {
File[] children = file.listFiles();
for (int i = 0; i < children.length; i++) {
@ -139,6 +143,7 @@ class PFMetadataLocation implements PFPersistenceLocation {
}
file.delete();
}
}
private File getContentsFile() {
File contentsFile = new File(_baseFolder, PFConstants.PROPERTIES_FILE_NAME);

View file

@ -42,7 +42,8 @@ interface PFPersistenceLocation {
/**
* @return the locations of the children of this location. It is possible
* for a location to have both contents and children.
* for a location to have both contents and children. Since this location
* is a handle it may not exist, in which case this returns an empty array.
*/
PFPersistenceLocation[] getChildren();
@ -63,6 +64,7 @@ interface PFPersistenceLocation {
/**
* Keeps only those children from this location that are in the keep set.
* Typically used to clean renamed nodes from the tree on a save operation.
* If the location does not yet exist, this does nothing.
* @param keepSet The names of the children that should be kept. Others are discarded.
*/
void keepChildren(Set keepSet);
@ -70,6 +72,7 @@ interface PFPersistenceLocation {
/**
* Sets the contents of this location to a particular stream.
* Implementations must close this stream when finished.
* This forces the location to come into existence if it does not already exist.
* @param stream the stream from which to read the new contents of this location.
*/
void setContents(InputStream stream);
@ -77,6 +80,7 @@ interface PFPersistenceLocation {
/**
* Returns an open stream which can be read to retrieve the contents of this
* location. The client is responsible for closing this stream.
* If the location does not yet exist this will return null and log the attempt.
* @return a stream that will retrieve the contents of this location.
*/
InputStream getContents();