You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2023/09/29 10:43:15 UTC

[aries] branch trunk updated: [ARIES-2108] Catch NoClassDefFoundError when loading Service-Providers

This is an automated email from the ASF dual-hosted git repository.

cschneider pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/aries.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 891b7318d [ARIES-2108] Catch NoClassDefFoundError when loading Service-Providers
     new 09b2d7593 Merge pull request #233 from HannesWell/noClassDefFoundError
891b7318d is described below

commit 891b7318d7925f58303ff8314660085c74a6d2cf
Author: Hannes Wellmann <we...@iils.de>
AuthorDate: Tue Jul 4 13:40:15 2023 +0200

    [ARIES-2108] Catch NoClassDefFoundError when loading Service-Providers
    
    Fixes https://issues.apache.org/jira/browse/ARIES-2108.
    
    Loading ServiceProvider instances, which depend on classes absent at
    runtime (e.g. because they are contained in an optional dependency)
    throws a NoClassDefFoundError instead of a ClassNotFoundException,
    which is propagated to the caller of
    ProviderBundleTrackerCustomizer.addingBundle() and leads to an empty
    list of providers.
    Instead a NoClassDefFoundError should be handled like a
    ClassNotFoundException.
    
    The reason for this different exception in this case is that although
    the service class is found it cannot be defined.
    
    The javadoc of 'NoClassDefFoundError' states:
    "Thrown if the Java Virtual Machine or a ClassLoader instance tries to
    load in the definition of a class (as part of a normal method call or as
    part of creating a new instance using the new expression) and no
    definition of the class could be found."
    
    The javadoc of 'ClassNotFoundException' states:
    "Thrown when an application tries to load in a class through its string
    name using:
    - The forName method in class Class.
    - The findSystemClass method in class ClassLoader .
    - The loadClass method in class ClassLoader.
    but no definition for the class with the specified name could be found."
---
 .../java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java b/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
index 178ec992c..974daec81 100644
--- a/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
+++ b/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
@@ -172,7 +172,7 @@ public class ProviderBundleTrackerCustomizer implements BundleTrackerCustomizer
 
                 activator.registerProviderBundle(details.serviceType, bundle, details.properties);
                 log(Level.INFO, "Registered provider " + details.instanceType + " of service " + details.serviceType + " in bundle " + bundle.getSymbolicName());
-            } catch (Exception e) {
+            } catch (Exception | NoClassDefFoundError e) {
                 log(Level.FINE,
                     "Could not load provider " + details.instanceType + " of service " + details.serviceType, e);
             }