avoid possible IllegalStateException if framework is stopped during CommandProxy method execution.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@947581 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
index ce7daed..cf59c09 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
@@ -38,23 +38,39 @@
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 @@
}
finally
{
- if (context != null)
- {
- context.ungetService(reference);
- }
+ ungetTarget();
}
}
}
\ No newline at end of file