Author: dbaum
Date: Mon May 24 09:47:59 2010
New Revision: 947581

URL: http://svn.apache.org/viewvc?rev=947581&view=rev
Log:
avoid possible IllegalStateException if framework is stopped during 
CommandProxy method execution.

Modified:
    
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java

Modified: 
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java?rev=947581&r1=947580&r2=947581&view=diff
==============================================================================
--- 
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
 (original)
+++ 
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
 Mon May 24 09:47:59 2010
@@ -38,23 +38,39 @@ public class CommandProxy implements Fun
         this.reference = reference;
         this.function = function;
     }
-    
+
     public CommandProxy(Object target, String function)
     {
         this.function = function;
         this.target = target;
     }
-    
+
     public Object getTarget()
     {
         return (context != null ? context.getService(reference) : target);
     }
 
+    public void ungetTarget()
+    {
+        if (context != null)
+        {
+            try
+            {
+                context.ungetService(reference);
+            }
+            catch (IllegalStateException e)
+            {
+                // ignore - probably due to shutdown
+                // java.lang.IllegalStateException: BundleContext is no longer 
valid
+            }
+        }
+    }
+
     public Object execute(CommandSession session, List<Object> arguments)
         throws Exception
     {
         Object tgt = getTarget();
-        
+
         try
         {
             if (tgt instanceof Function)
@@ -68,10 +84,7 @@ public class CommandProxy implements Fun
         }
         finally
         {
-            if (context != null)
-            {
-                context.ungetService(reference);
-            }
+            ungetTarget();
         }
     }
 }
\ No newline at end of file


Reply via email to