Skip to content

Commit

Permalink
ISPN-3592 Avoid the DirectoryImplementor list() method to return null…
Browse files Browse the repository at this point in the history
… elements in the returned array
  • Loading branch information
Sanne committed Oct 6, 2013
1 parent cc6f8c9 commit 838a1ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -143,8 +143,13 @@ public InfinispanDirectory(Cache<?, ?> cache) {
*/
public String[] list() {
ensureOpen();
Set<String> filesList = fileOps.getFileList();
return filesList.toArray(new String[filesList.size()]);
Set<String> files = fileOps.getFileList();
//Careful! if you think you can optimize this array allocation, think again.
//The _files_ are a concurrent structure, its size could vary in parallel:
//the array population and dimensioning need to be performed atomically
//to avoid trailing null elements in the returned array.
String[] array = files.toArray(new String[0]);
return array;
}

/**
Expand Down
Expand Up @@ -51,8 +51,13 @@ public DirectoryImplementor(Cache<?, ?> metadataCache, Cache<?, ?> chunksCache,
}

String[] list() {
final Set<String> filesList = fileOps.getFileList();
return filesList.toArray(new String[filesList.size()]);
final Set<String> files = fileOps.getFileList();
//Careful! if you think you can optimize this array allocation, think again.
//The _files_ are a concurrent structure, its size could vary in parallel:
//the array population and dimensioning need to be performed atomically
//to avoid trailing null elements in the returned array.
final String[] array = files.toArray(new String[0]);
return array;
}

boolean fileExists(final String name) {
Expand Down

0 comments on commit 838a1ae

Please sign in to comment.