incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r981444 - /sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
Date Mon, 02 Aug 2010 10:27:37 GMT
Author: fmeschbe
Date: Mon Aug  2 10:27:36 2010
New Revision: 981444

URL: http://svn.apache.org/viewvc?rev=981444&view=rev
Log:
SLING-1625 Check File.listFiles() result to prevent NullPointerException

Modified:
    sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java

Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java?rev=981444&r1=981443&r2=981444&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
(original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
Mon Aug  2 10:27:36 2010
@@ -163,22 +163,28 @@ public class FileMonitor extends TimerTa
                     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 TimerTa
         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];
             }
         }
     }



Mime
View raw message