You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2015/08/06 10:57:28 UTC

incubator-lens git commit: LENS-712 : Fixes NPE while initializing ScannedPaths

Repository: incubator-lens
Updated Branches:
  refs/heads/master e6f585b73 -> e5a0ff19a


LENS-712 : Fixes NPE while initializing ScannedPaths


Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/e5a0ff19
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/e5a0ff19
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/e5a0ff19

Branch: refs/heads/master
Commit: e5a0ff19aa179fbc858dbb3f70308186875ec728
Parents: e6f585b
Author: Yash Sharma <ya...@gmail.com>
Authored: Thu Aug 6 14:26:50 2015 +0530
Committer: Rajat Khandelwal <pr...@apache.org>
Committed: Thu Aug 6 14:26:50 2015 +0530

----------------------------------------------------------------------
 .../apache/lens/server/util/ScannedPaths.java   | 31 +++++++++++---------
 1 file changed, 17 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e5a0ff19/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java b/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
index 92687c3..4143525 100644
--- a/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
+++ b/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
@@ -23,7 +23,6 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -69,7 +68,8 @@ public class ScannedPaths implements Iterable<String> {
    */
   private List<String> getMatchedPaths(String path, String type) {
     List<String> finalPaths = new ArrayList<>();
-    FileSystem fs;
+    InputStream resourceOrderIStream = null;
+    FileSystem fs = null;
 
     try {
       fs = FileSystem.get(new URI(path), new Configuration());
@@ -85,7 +85,6 @@ public class ScannedPaths implements Iterable<String> {
          * CASE 2 : DIR provided in path
          **/
         Path resourceOrderFile = null;
-        InputStream resourceOrderIStream = null;
         FileStatus[] statuses;
         List<String> newMatches;
         List<String> resources;
@@ -99,8 +98,10 @@ public class ScannedPaths implements Iterable<String> {
           if (!fs.exists(resourceOrderFile)) {
             /** Get matched resources recursively for all files **/
             statuses = fs.globStatus(new Path(pt, "*"));
-            for (FileStatus st : statuses) {
-              finalPaths.add(st.getPath().toUri().toString());
+            if (statuses != null) {
+              for (FileStatus st : statuses) {
+                finalPaths.add(st.getPath().toUri().toString());
+              }
             }
           } else {
             resourceFileFound = true;
@@ -135,10 +136,12 @@ public class ScannedPaths implements Iterable<String> {
          * CASE 3 : REGEX provided in path
          * */
         FileStatus[] statuses = fs.globStatus(pt);
-        for (FileStatus st : statuses) {
-          List<String> newMatches = getMatchedPaths(st.getPath().toString(), type);
-          if (newMatches != null) {
-            finalPaths.addAll(newMatches);
+        if (statuses != null) {
+          for (FileStatus st : statuses) {
+            List<String> newMatches = getMatchedPaths(st.getPath().toString(), type);
+            if (newMatches != null) {
+              finalPaths.addAll(newMatches);
+            }
           }
         }
       }
@@ -146,11 +149,11 @@ public class ScannedPaths implements Iterable<String> {
       filterDirsAndJarType(fs, finalPaths);
 
     } catch (FileNotFoundException fex) {
-      log.error("File not found while scanning path.", fex);
-    } catch (URISyntaxException | IOException ex) {
-      log.error("Exception while initializing PathScanner.", ex);
+      log.error("File not found while scanning path. Path: {}, Type: {}", path, type, fex);
     } catch (Exception e) {
-      log.error("Exception while initializing PathScanner.", e);
+      log.error("Exception while initializing PathScanner. Path: {}, Type: {}", path, type, e);
+    } finally {
+      IOUtils.closeQuietly(resourceOrderIStream);
     }
 
     return finalPaths;
@@ -174,7 +177,7 @@ public class ScannedPaths implements Iterable<String> {
         }
       }
     } catch (IOException e) {
-      log.error("Exception while initializing filtering dirs.", e);
+      log.error("Exception while initializing filtering dirs", e);
     }
   }
 }