You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/01/18 14:06:09 UTC

svn commit: r613150 - /incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java

Author: fmeschbe
Date: Fri Jan 18 05:06:07 2008
New Revision: 613150

URL: http://svn.apache.org/viewvc?rev=613150&view=rev
Log:
SLING-158 Test result from getResourceInternal to prevent NPE

Modified:
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java?rev=613150&r1=613149&r2=613150&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java Fri Jan 18 05:06:07 2008
@@ -91,8 +91,14 @@
      */
     public InputStream getInputStream(String fileName)
             throws FileNotFoundException, IOException {
+        
         try {
+            
             Resource resource = getResourceInternal(fileName);
+            if (resource == null) {
+                throw new FileNotFoundException("Cannot find " + fileName);
+            }
+            
             InputStream stream = resource.adaptTo(InputStream.class);
             if (stream == null) {
                 throw new FileNotFoundException("Cannot find " + fileName);
@@ -230,14 +236,15 @@
 
     /* package */URL getURL(String path) throws MalformedURLException {
         try {
-            return getResourceInternal(path).adaptTo(URL.class);
+            Resource resource = getResourceInternal(path);
+            return (resource != null) ? resource.adaptTo(URL.class) : null;
         } catch (SlingException se) {
             throw (MalformedURLException) new MalformedURLException(
                 "Cannot get URL for " + path).initCause(se);
         }
     }
 
-    /* package */ Set<String> getResourcePaths(String path) {
+    /* package */Set<String> getResourcePaths(String path) {
         Set<String> paths = new HashSet<String>();
 
         ResourceResolver resolver = requestResourceResolver.get();
@@ -251,7 +258,8 @@
                     }
                 }
             } catch (SlingException se) {
-                log.warn("getResourcePaths: Cannot list children of " + path, se);
+                log.warn("getResourcePaths: Cannot list children of " + path,
+                    se);
             }
         }
 
@@ -355,8 +363,8 @@
                     if (lastSlash <= 0) {
                         parentNode = session.getRootNode();
                     } else {
-                        Item parent = session.getItem(fileName.substring(
-                            0, lastSlash));
+                        Item parent = session.getItem(fileName.substring(0,
+                            lastSlash));
                         if (!parent.isNode()) {
                             // TODO: fail
                         }