This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.6.x-fixes by this push:
new 02783b842c Fix possible IllegalStateException when bundle is stopped
(#2144)
02783b842c is described below
commit 02783b842cbc3ab8b72c0bf971ef22087fa53603
Author: Thomas Watson <[email protected]>
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 f553155ed7..9839eb5f2b 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
@@ -106,14 +106,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) {
@@ -123,6 +123,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<>(