[ 
https://issues.apache.org/jira/browse/ARIES-2108?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Hannes Wellmann updated ARIES-2108:
-----------------------------------
    Description: 
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:
{code:java}
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.{code}
The javadoc of {{ClassNotFoundException}} states:
{code:java}
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.{code}
One example where this scenario occurs is Logback for SLF4J-2. Besides the 
{{SLF4JServiceProvider}} service this bundle also provides a 
{{{}ServletContainerInitializer{}}}, which is only relevant/intended for 
server/web-app environments where an implementation of the 
{{jakarta./javax.servlet}} API is provided.
Therefore the maven dependencies for {{jakarta./javax.servlet}} are in the 
provided scope and optional and correspondingly the {{jakarta./javax.servlet}} 
packages are only optionally imported in the MANIFEST.MF.

[https://github.com/qos-ch/logback/blob/4e069d34d9422a43511ae7d6242a27caa8834e14/logback-classic/pom.xml#L335-L356]

  was:
Loading ServiceProvider instances that depend on classes that are 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 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:
{code:java}
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.{code}

The javadoc of {{ClassNotFoundException}} states:
{code:java}
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.{code}
One example where this scenario occurs is Logback for SLF4J-2. Besides the 
{{SLF4JServiceProvider}} service this bundle also provides a 
{{{}ServletContainerInitializer{}}}, which is only relevant/intended for 
server/web-app environments where an implementation of the 
{{jakarta./javax.servlet}} API is provided.
Therefore the maven dependencies for {{jakarta./javax.servlet}} are in the 
provided scope and optional and correspondingly the {{jakarta./javax.servlet}} 
packages are only optionally imported in the MANIFEST.MF.

https://github.com/qos-ch/logback/blob/4e069d34d9422a43511ae7d6242a27caa8834e14/logback-classic/pom.xml#L335-L356


> Catch 'NoClassDefFoundError' when loading Service-Provider instances
> --------------------------------------------------------------------
>
>                 Key: ARIES-2108
>                 URL: https://issues.apache.org/jira/browse/ARIES-2108
>             Project: Aries
>          Issue Type: Bug
>          Components: SPI Fly
>    Affects Versions: spifly-1.3.6
>            Reporter: Hannes Wellmann
>            Priority: Major
>
> 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:
> {code:java}
> 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.{code}
> The javadoc of {{ClassNotFoundException}} states:
> {code:java}
> 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.{code}
> One example where this scenario occurs is Logback for SLF4J-2. Besides the 
> {{SLF4JServiceProvider}} service this bundle also provides a 
> {{{}ServletContainerInitializer{}}}, which is only relevant/intended for 
> server/web-app environments where an implementation of the 
> {{jakarta./javax.servlet}} API is provided.
> Therefore the maven dependencies for {{jakarta./javax.servlet}} are in the 
> provided scope and optional and correspondingly the 
> {{jakarta./javax.servlet}} packages are only optionally imported in the 
> MANIFEST.MF.
> [https://github.com/qos-ch/logback/blob/4e069d34d9422a43511ae7d6242a27caa8834e14/logback-classic/pom.xml#L335-L356]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to