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 2011/12/22 08:33:02 UTC

svn commit: r1222080 - /sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java

Author: fmeschbe
Date: Thu Dec 22 07:33:02 2011
New Revision: 1222080

URL: http://svn.apache.org/viewvc?rev=1222080&view=rev
Log:
SLIGN-2341 Apply slightly modified patch by Julian Sedding (thanks alot!)
  - A temporary variable srv is used to be able to apply the @SuppressWarnings("unchecked")
    annotation to this assignment instead of to the method

Modified:
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java?rev=1222080&r1=1222079&r2=1222080&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java (original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java Thu Dec 22 07:33:02 2011
@@ -19,6 +19,7 @@
 package org.apache.sling.scripting.core;
 
 import java.io.IOException;
+import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -220,7 +221,6 @@ public class ScriptHelper implements Sli
     /**
      * @see org.apache.sling.api.scripting.SlingScriptHelper#getServices(java.lang.Class, java.lang.String)
      */
-    @SuppressWarnings("unchecked")
     public <ServiceType> ServiceType[] getServices(
             Class<ServiceType> serviceType, String filter)
     throws InvalidServiceFilterSyntaxException {
@@ -231,6 +231,7 @@ public class ScriptHelper implements Sli
             if (refs != null) {
                 final List<ServiceType> objects = new ArrayList<ServiceType>();
                 for (int i = 0; i < refs.length; i++) {
+                    @SuppressWarnings("unchecked")
                     final ServiceType service = (ServiceType) this.bundleContext.getService(refs[i]);
                     if (service != null) {
                         if ( this.references == null ) {
@@ -241,7 +242,9 @@ public class ScriptHelper implements Sli
                     }
                 }
                 if (objects.size() > 0) {
-                    result = (ServiceType[]) objects.toArray();
+                    @SuppressWarnings("unchecked")
+                    ServiceType[] srv = (ServiceType[]) Array.newInstance(serviceType, objects.size());
+                    result = objects.toArray(srv);
                 }
             }
             return result;