You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2022/02/10 10:57:08 UTC

[GitHub] [sling-org-apache-sling-models-impl] Buuhuu commented on a change in pull request #34: SLING-11132 - Exception handling while clearing OSGiServiceReferences

Buuhuu commented on a change in pull request #34:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/34#discussion_r803547697



##########
File path: src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
##########
@@ -204,7 +204,11 @@ public Callback(ServiceReference<?>[] refs, BundleContext context) {
         public void onDisposed() {
             if (refs != null) {
                 for (ServiceReference<?> ref : refs) {
-                    context.ungetService(ref);
+                    try {
+                        context.ungetService(ref);
+                    } catch (IllegalStateException | IllegalArgumentException | NullPointerException exception) {

Review comment:
       I think it is a valid case to catch all these RuntimeExceptions to guarantee that the iteration over the ServiceReference completes. However, as you don't handle the exceptions you may want to collect them instead and add them as suppressed exceptions to a new `RuntimeException` that you throw if any exception happened during the iteration. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org