SLING-9599 - Incomplete non-existing resource check

* make sure the resource obtained can be adapted to a stream
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/use/DependencyResolver.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/use/DependencyResolver.java
index 7b0a09e..fb97c12 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/use/DependencyResolver.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/use/DependencyResolver.java
@@ -120,10 +120,15 @@
             }
 
             if (scriptResource == null) {
-                throw  new SightlyException(String.format("Unable to load script dependency %s.", dependency));
+                throw new SightlyException(String.format("Unable to load script dependency %s.", dependency));
             }
-            reader = new ScriptNameAwareReader(new StringReader(IOUtils.toString(scriptResource.adaptTo(InputStream.class),
-                    StandardCharsets.UTF_8)), scriptResource.getPath());
+            InputStream scriptStream = scriptResource.adaptTo(InputStream.class);
+            if (scriptStream == null) {
+                throw new SightlyException(String.format("Unable to read script %s.", dependency));
+            }
+            reader = new ScriptNameAwareReader(new StringReader(IOUtils.toString(scriptStream, StandardCharsets.UTF_8)),
+                    scriptResource.getPath());
+            IOUtils.closeQuietly(scriptStream);
         } catch (IOException e) {
             ioException = e;
         }