SLING-11132: Exception handling while clearing OSGiServiceReferences (#34)
* SLING-11132 - Exception handling while clearing OSGiServiceReferences
* SLING-11132 - Catch only IllegalStateException
* SLING-11132 - Remove log from catch block
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
index 08f6d35..ce4d30d 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
@@ -204,7 +204,11 @@
public void onDisposed() {
if (refs != null) {
for (ServiceReference<?> ref : refs) {
- context.ungetService(ref);
+ try {
+ context.ungetService(ref);
+ } catch (IllegalStateException exception) {
+ // SLING-11132 - This exception is expected when BundleContext is no longer valid.
+ }
}
}
}