[jira] [Updated] (ARIES-2108) Catch 'NoClassDefFoundError' when loading Service-Provider instances

2023-07-04 Thread Hannes Wellmann (Jira)


 [ 
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 

[GitHub] [aries] HannesWell opened a new pull request, #233: Catch 'NoClassDefFoundError' when loading Service-Provider instances

2023-07-04 Thread via GitHub


HannesWell opened a new pull request, #233:
URL: https://github.com/apache/aries/pull/233

   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 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.
   ```
   
   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 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-unsubscr...@aries.apache.org

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



[jira] [Created] (ARIES-2108) Catch 'NoClassDefFoundError' when loading Service-Provider instances

2023-07-04 Thread Hannes Wellmann (Jira)
Hannes Wellmann created ARIES-2108:
--

 Summary: 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


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



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