felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vvalc...@apache.org
Subject svn commit: r1391982 - /felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ControlServlet.java
Date Sun, 30 Sep 2012 10:32:31 GMT
Author: vvalchev
Date: Sun Sep 30 10:32:31 2012
New Revision: 1391982

URL: http://svn.apache.org/viewvc?rev=1391982&view=rev
Log:
Fixed FELIX-3669 : NPE in ControlServlet.deviceToJSON
https://issues.apache.org/jira/browse/FELIX-3669

Modified:
    felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ControlServlet.java

Modified: felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ControlServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ControlServlet.java?rev=1391982&r1=1391981&r2=1391982&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ControlServlet.java
(original)
+++ felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ControlServlet.java
Sun Sep 30 10:32:31 2012
@@ -55,6 +55,8 @@ import org.osgi.util.tracker.ServiceTrac
 public class ControlServlet extends HttpServlet implements ServiceTrackerCustomizer
 {
 
+    private static final long serialVersionUID = -5789642544511401813L;
+
     private static final SimpleDateFormat DATA_FORMAT = new SimpleDateFormat(
         "EEE, d MMM yyyy HH:mm:ss Z"); //$NON-NLS-1$
 
@@ -227,8 +229,11 @@ public class ControlServlet extends Http
 
     private final JSONObject deviceTreeToJSON(ServiceReference ref) throws JSONException
     {
-        UPnPDevice device = (UPnPDevice) tracker.getService(ref);
-        Object[] refs = tracker.getServiceReferences();
+        final UPnPDevice device = (UPnPDevice) tracker.getService(ref);
+        if (null == device)
+        {
+            return null; // the device is dynamically removed
+        }
 
         Object parentUdn = ref.getProperty(UPnPDevice.UDN);
         if (parentUdn == null)
@@ -241,6 +246,7 @@ public class ControlServlet extends Http
         JSONObject json = deviceToJSON(ref, device);
 
         // add child devices
+        final Object[] refs = tracker.getServiceReferences();
         for (int i = 0; refs != null && i < refs.length; i++)
         {
             ref = (ServiceReference) refs[i];
@@ -257,7 +263,6 @@ public class ControlServlet extends Http
             }
             else if (parentUdn.equals(parent))
             {
-                device = (UPnPDevice) tracker.getService(ref);
                 JSONObject deviceJSON = deviceTreeToJSON(ref);
                 if (null != deviceJSON)
                 {
@@ -456,14 +461,19 @@ public class ControlServlet extends Http
             _udn = (String) refs[i].getProperty(UPnPDevice.UDN);
             if (_udn != null && _udn.equals(udn))
             {
-                return (UPnPDevice) tracker.getService(refs[i]);
+                UPnPDevice upnpDevice = (UPnPDevice) tracker.getService(refs[i]);
+                if (null == upnpDevice)
+                {
+                    break; // device not found
+                }
+                return upnpDevice;
             }
         }
 
         throw new IllegalArgumentException("Device '" + udn + "' not found!");
     }
 
-    private final UPnPService getService(UPnPDevice device, String urn)
+    private static final UPnPService getService(UPnPDevice device, String urn)
     {
         UPnPService[] services = device.getServices();
         for (int i = 0; services != null && i < services.length; i++)



Mime
View raw message