You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2024/11/16 16:39:14 UTC
(cxf) branch 3.5.x-fixes updated: Fix possible IllegalStateException when bundle is stopped (#2144)
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.5.x-fixes by this push:
new a9683e05e8 Fix possible IllegalStateException when bundle is stopped (#2144)
a9683e05e8 is described below
commit a9683e05e83042d14e7fcbf8f7b9c74fb54800ce
Author: Thomas Watson <tj...@gmail.com>
AuthorDate: Sat Nov 16 10:39:09 2024 -0600
Fix possible IllegalStateException when bundle is stopped (#2144)
If a failure occurs while trying to register the service ignore
it. The IllegalStateException will have occurred because the
bundle is stopped. The ManagedService will have been
unregistered or is about to be automatically by the framework.
There is no need to handle or throw the exception here because
the bundles services will have been automatically cleaned
up by the framework when the bundle was stopped.
---
.../java/org/apache/cxf/ext/logging/osgi/Activator.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
index 4534dd7b10..b46a439ded 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
@@ -104,14 +104,14 @@ public class Activator implements BundleActivator {
if (intentReg == null) {
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("org.apache.cxf.dosgi.IntentName", "logging");
- bundleContext.registerService(AbstractFeature.class.getName(), logging, properties);
+ intentReg = safeRegister(AbstractFeature.class.getName(), logging, properties);
}
if (enabled) {
if (serviceReg == null) {
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("name", "logging");
- serviceReg = bundleContext.registerService(Feature.class.getName(), logging, properties);
+ serviceReg = safeRegister(Feature.class.getName(), logging, properties);
}
} else {
if (serviceReg != null) {
@@ -121,6 +121,16 @@ public class Activator implements BundleActivator {
}
}
+ private ServiceRegistration<?> safeRegister(String name, Object service,
+ Dictionary<String, Object> properties) {
+ try {
+ return bundleContext.registerService(name, service, properties);
+ } catch (IllegalStateException e) {
+ // ignore, likely the bundle is stopped
+ return null;
+ }
+ }
+
@SuppressWarnings("rawtypes")
private Set<String> getTrimmedSet(Dictionary config, String propertyKey) {
return new HashSet<>(