This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.0.2 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 61509be0b78adc25c48529c21d0463351ea01593 Author: Felix Meschberger <[email protected]> AuthorDate: Mon Aug 2 10:27:36 2010 +0000 SLING-1625 Check File.listFiles() result to prevent NullPointerException git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@981444 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/fsprovider/internal/FileMonitor.java | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java index 5e03ea9..336f1c1 100644 --- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java +++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java @@ -163,22 +163,28 @@ public class FileMonitor extends TimerTask { if ( changed ) { // and now update final File[] files = monitorable.file.listFiles(); - final Monitorable[] children = new Monitorable[files.length]; - for(int i=0; i<files.length; i++) { - // search in old list - for(int m=0;m<ds.children.length;m++) { - if ( ds.children[m].file.equals(files[i]) ) { - children[i] = ds.children[m]; - break; + if (files != null) { + final Monitorable[] children = new Monitorable[files.length]; + for (int i = 0; i < files.length; i++) { + // search in old list + for (int m = 0; m < ds.children.length; m++) { + if (ds.children[m].file.equals(files[i])) { + children[i] = ds.children[m]; + break; + } + } + if (children[i] == null) { + children[i] = new Monitorable( + monitorable.path + '/' + + files[i].getName(), files[i]); + children[i].status = NonExistingStatus.SINGLETON; + check(children[i], localEA); } } - if ( children[i] == null ) { - children[i] = new Monitorable(monitorable.path + '/' + files[i].getName(), files[i]); - children[i].status = NonExistingStatus.SINGLETON; - check(children[i], localEA); - } + ds.children = children; + } else { + ds.children = new Monitorable[0]; } - ds.children = children; } } } @@ -241,10 +247,15 @@ public class FileMonitor extends TimerTask { public DirStatus(final File dir, final String path) { super(dir); final File[] files = dir.listFiles(); - this.children = new Monitorable[files.length]; - for(int i=0; i<files.length; i++) { - this.children[i] = new Monitorable(path + '/' + files[i].getName(), files[i]); - FileMonitor.createStatus(this.children[i]); + if (files != null) { + this.children = new Monitorable[files.length]; + for (int i = 0; i < files.length; i++) { + this.children[i] = new Monitorable(path + '/' + + files[i].getName(), files[i]); + FileMonitor.createStatus(this.children[i]); + } + } else { + this.children = new Monitorable[0]; } } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
