incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r578250 - /incubator/sling/trunk/scripting-core/src/main/java/org/apache/sling/scripting/ScriptedComponent.java
Date Fri, 21 Sep 2007 20:08:43 GMT
Author: fmeschbe
Date: Fri Sep 21 13:08:43 2007
New Revision: 578250

URL: http://svn.apache.org/viewvc?rev=578250&view=rev
Log:
SLING-15 NPE if the scripted component hasn't sling:scripts node created

Modified:
    incubator/sling/trunk/scripting-core/src/main/java/org/apache/sling/scripting/ScriptedComponent.java

Modified: incubator/sling/trunk/scripting-core/src/main/java/org/apache/sling/scripting/ScriptedComponent.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting-core/src/main/java/org/apache/sling/scripting/ScriptedComponent.java?rev=578250&r1=578249&r2=578250&view=diff
==============================================================================
--- incubator/sling/trunk/scripting-core/src/main/java/org/apache/sling/scripting/ScriptedComponent.java
(original)
+++ incubator/sling/trunk/scripting-core/src/main/java/org/apache/sling/scripting/ScriptedComponent.java
Fri Sep 21 13:08:43 2007
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.TreeSet;
 
 import org.apache.sling.component.Component;
@@ -145,9 +146,12 @@
     protected Script getScript(ComponentRequest request) {
 
         // check whether we can handle the script
-        for (int i = 0; i < this.scripts.length && this.scripts[i] != null; i++)
{
-            if (this.scripts[i].matches(request)) {
-                return this.scripts[i];
+        Script[] scripts = this.scripts;
+        if (scripts != null) {
+            for (int i = 0; i < this.scripts.length && this.scripts[i] != null;
i++) {
+                if (this.scripts[i].matches(request)) {
+                    return this.scripts[i];
+                }
             }
         }
 
@@ -266,14 +270,22 @@
     }
 
     public void setScripts(Collection scripts) {
-        TreeSet scriptSet = new TreeSet();
-        if (scripts != null && !scripts.isEmpty()) {
-            scriptSet.addAll(scripts);
+        if (scripts == null || scripts.isEmpty()) {
+            this.scripts = null;
+        } else {
+            TreeSet scriptSet = new TreeSet();
+            if (scripts != null && !scripts.isEmpty()) {
+                scriptSet.addAll(scripts);
+            }
+            this.scripts = (Script[]) scriptSet.toArray(new Script[scriptSet.size()]);
         }
-        this.scripts = (Script[]) scriptSet.toArray(new Script[scriptSet.size()]);
     }
 
     public Collection getScripts() {
+        if (scripts == null) {
+            return Collections.emptyList();
+        }
+        
         return Arrays.asList(this.scripts);
     }
 



Mime
View raw message